Good day. My question is probably stupid, but I just can not figure it out. I need to do image decoding:

BitmapFactory.decodeFile( /* PATH TO PIC */, options); 

But my images are stored in an array (drawable):

  public Integer[] myPics = { R.drawable.pic1, R.drawable.pic2, R.drawable.pic3, R.drawable.pic4, R.drawable.pic5, R.drawable.pic6, R.drawable.pic7, R.drawable.pic8, R.drawable.pic9, R.drawable.pic10, R.drawable.pic11, R.drawable.pic12, R.drawable.pic13, R.drawable.pic14, R.drawable.pic15, R.drawable.pic16, R.drawable.pic17, R.drawable.pic18, R.drawable.pic19, R.drawable.pic20, R.drawable.pic21 }; 

The decodeFile method in the first parameter receives only the string path. I tried to get an element from an array by position or element number, but all this does not fit. Actually a subject

* UPD tried through decode resources, but he also doesn’t want to work with decodeResource(mContext.getResources(), mThumbIds[path], options);

    2 answers 2

    It is impossible to get the path to the file from the unique ID generated at compilation, which are the constants of class R that fill your array.

    You may need to remake the method to accept a Bitmap object.

    • It is clear, we will think. But then the second question immediately follows, I display the images in the GridView, there are only 20 of them. Without decoding, they are output, but scrolling terribly slowly on both the Genymotion emulator and the real device. After successful decoding, the situation will change or is it something else? - ivanovd422
    • @ Denis422, maybe they are big too. Try their specials. To display and not independently. For example Picasso, Glide - YuriySPb

    The problem was solved using the standard Google image decoding solution tyk

      imageView.setImageBitmap( decodeSampledBitmapFromResource(mContext.getResources(),mThumbIds[position], 100, 100));