BitmapFactory returns bigger image than source

reduce bitmap size android
bitmap.createbitmap out of memory android
loading large bitmaps efficiently android
failed to create image decoder with message 'unimplemented picasso
android compress bitmap without losing quality programmatically
how to display large images in android
how to get bitmap image size in android
android bitmap

Hi i am creating a Bitmap from an png image named image.png. The image has the dimension 75 (width) x 92 (height). When I run this code:

Bitmap bitmap = BitmapFactory.decodeResource(this.context.getResources(),  R.drawable.image
Log.d("image", "height: " + bitmap.getHeight() + " width: " + bitmap.getWidth());

the logger logs:

DEBUG/image(3550): height: 138 width: 113

and the image on the screen is bigger than other images which have the dimension 75 x 92. What can I do to make android load the image with the right dimension?


My solution:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;               
Bitmap bitmap = BitmapFactory.decodeResource(this.context.getResources(),  R.drawable.image, options );

BitmapFactory returns bigger image than source, Hi i am creating a Bitmap from an png image named image.png. The image has the dimension 75 (width) x 92 (height). When I run this code: Bitmap bitmap  Without using Gravity.Fill though the image is actually still bigger than the ImageView, so wastes resources. On the device I'm on now the Density is 1.5 and that is about how much bigger the picture is. On other devices the image may be even bigger than needed with higher density.


It sounds like your screen density on your device is different than the density where image.png was created.

If you really want to prevent the scaling, you could try one of the following:

  1. Put the image in res/drawable-nodpi (http://developer.android.com/guide/practices/screens_support.html#qualifiers)

  2. Use ImageView.ScaleType.CENTER (http://developer.android.com/reference/android/widget/ImageView.ScaleType.html)

  3. Just found this related question on SO: Android: How to stop Android 1.6+ from scaling images

Loading Large Bitmaps Efficiently, In many cases they are larger than required for a typical application user Choose the most appropriate decode method based on your image data source. returning null for the bitmap object but setting outWidth , outHeight  BitmapFactory returns bigger image than source. Hi i am creating a Bitmap from an png image named image.png. The image has the dimension 75 (width) x 92 (height).


Beause loader in BitmapFactory applies screen density scaling during loading. To override this, provide own desired inTargetDensity in BitmapFactory.Options in call to decodeResource.

Android High Performance Programming, The BitmapFactory class provides different methods to load an image If we are dealing with very big images, we can use a special API to decode small To find out, we want to get image dimensions without reading the whole source bitmap. is set to define whether the decoding method should return a Bitmap object. Android Platform. API level 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1. Manifest.permission. Manifest.permission_group. android.accessibilityservice. AccessibilityService.MagnificationController.OnMagnificationChangedListener. AccessibilityService.SoftKeyboardController.OnShowModeChangedListener.


Bitmap thumbImage = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(context.getResources(), R.drawable.image), 640, 640, false);

Pro Android 3, setImageBitmap(BitmapFactory. The third definition does not specify an image source in the XML, but we have an ID associated to dimensions of the image on the screen and define what to do if the image is larger than our maximum size. The ideia is to load a image from internal memory and show on ImageView. The problem is that BitmapFactory.decodeByteArray is always returning null for the image loaded. OBS: R.raw.teste is a valid image. OBS2: The for block is there only because the code was intended to fill a ListView.


Pro Android 4, The third definition does not specify an image source in the XML, but we of the image on the screen and define what to do if the image is larger than our the BitmapFactory to read in an image resource into a Bitmap object and then sets the  /** * Calculate an inSampleSize for use in a {@link android.graphics.BitmapFactory.Options} object when decoding * bitmaps using the decode* methods from {@link android.graphics.BitmapFactory}. This implementation calculates * the closest inSampleSize that is a power of 2 and will result in the final decoded bitmap * having a width and height


Working with the ImageView, The ImageView handles all the loading and scaling of the image for you. We can also size an ImageView at runtime within our Java source code by modifying the width y dimensions are greater than or equal to the view, while maintaining the image aspect ratio; centers the image in the view. getWidth(); return Bitmap. null-ok; Options that control downsampling and whether the image should be completely decoded, or just is size returned. Returns The decoded bitmap, or null if the image data could not be decoded, or, if opts is non-null, if opts requested only the size be returned (in opts.outWidth and opts.outHeight)


Pro Android 5, image files where we not only specify the source of the image file but also set of the image on the screen and define what to do if the image is larger than our the BitmapFactory to read in an image resource into a Bitmap object and then  The image store2.png is 519,8 KiB, while store.png is 462,0 KiB. Why is that the case? Does the PImage type wrap the image with some useless bytes on loading/saving? If yes, is it possible to get rid of them to have a perfect copy of the original image? My current project involves having the smallest images possible for storage reasons.