11

I have image with 543*6423 resolution, I want to display it in all devices. It is displaying in few of android phones which allows the high resolution. I tried with

android:hardwareAccelerated="false"

This is my java code for android client

File storagePath =Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_DOWNLOADS+
                    "abc.png");
            InputStream is = this.getContentResolver().openInputStream(Uri.fromFile(storagePath)); 
            Bitmap b = BitmapFactory.decodeStream(is, null, null); 
            is.close(); 
            image.setImageBitmap(b);

This worked in my mobile (sony xperia) but few other phones are not displaying it. Please help me how can I display this image independent of screen resolution.

Thanks, Aman

Amandeep Singh
  • 3,754
  • 8
  • 51
  • 72
  • 1
    see [this](http://stackoverflow.com/a/15136744/1289716) answer, hope it will help you. – MAC Mar 03 '13 at 05:40
  • http://stackoverflow.com/questions/22633638/prevent-bitmap-too-large-to-be-uploaded-into-a-texture-android/24123605#24123605 Check out my answer – Gilbert92 Jun 09 '14 at 15:43

5 Answers5

4

Your image is probably too large to be displayed on most devices. So you have to load a scaled down version of the image. Look at Loading Large Bitmaps Efficiently to see how to do this and calculate an appropriate sample size. If you need the display width / height (in case of a full screen image) you can use getResources().getDisplayMetrics().

FahneImWind
  • 146
  • 6
4

try with

android:hardwareAccelerated="false" 
android:largeHeap="true"
NgSon
  • 51
  • 1
0

Well, maybe I am too late to help you but this can hopefully help others. I've recently developed an open source library that can handle large image loading. The source code and samples are available at https://github.com/diegocarloslima/ByakuGallery

diegocarloslima
  • 1,346
  • 14
  • 16
0

The solution in the blog is wrong by a power of 2...

Here is the solution:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;

// Set height and width in options, does not return an image and no resource taken
BitmapFactory.decodeStream(imagefile, null, options);

int pow = 0;
while (options.outHeight >> pow > reqHeight || options.outWidth >> pow > reqWidth)
    pow += 1;
options.inSampleSize = 1 << pow; 
options.inJustDecodeBounds = false;
image = BitmapFactory.decodeStream(imagefile, null, options);

The image will be scaled down at the size of reqHeight and reqWidth. As I understand inSampleSize only take in a power of 2 values.

vtlinh
  • 1,427
  • 3
  • 11
  • 16
0

Instead of spending hours upon hours trying to write and debug all this downsampling code manually, why not try using Picasso? It is a popular image loading library and was made for dealing with bitmaps of all types and/or sizes. I have used this single line of code to remove my "bitmap too large...." problem:

Picasso.with(image.getContext()).load(storagePath).fit().centerCrop().into(image);
Phileo99
  • 5,581
  • 2
  • 46
  • 54