Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i am displaying my images from assests/image folder , but this code is not working . this code display images from assets folder in gallery . i am using gallery prefine library or jar file.

please expert check it . thank u

AssetManager assetManager = getAssets();
    String[] files = null;
    try {
        files = assetManager.list("image");
    } catch (IOException e) {
        Log.e("tag", e.getMessage());
    }

    for(String filename : files) {
        System.out.println("File name => "+filename);
        InputStream in = null;
        try {
            ImageViewTouch imageView = new ImageViewTouch(Rahul.this); 
            imageView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
          final Options options = new Options();
            options.outHeight = (int) scaleHeight; 
            options.outWidth = (int) scaleWidth;   
            options.inScaled = true;
            options.inPurgeable = true;
            options.inSampleSize = 2;
           in = assetManager.open("image/"+filename); 
           Bitmap bit=BitmapFactory.decodeStream(in);

          imageView.setImageBitmap(bit);

              } catch(Exception e) {
            Log.e("tag", e.getMessage());
        }
    }
    gallery.setAdapter(arrayAdapter);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
224 views
Welcome To Ask or Share your Answers For Others

1 Answer

Hey please check my answer on the same issue: bitmap size exceeds Vm budget error android

And also always try to use maximum options while dealing with bitmaps like this:

 final Options options = new Options();
    options.outHeight = (int) scaleHeight; // new smaller height
    options.outWidth = (int) scaleWidth;   // new smaller width
    options.inScaled = true;
    options.inPurgeable = true;

    // to scale the image to 1/8
    options.inSampleSize = 8;
    bitmap = BitmapFactory.decodeFile(imagePath, options);

This might solve your problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...