BitmapFactory returns bigger image than source

后端 未结 4 1917
隐瞒了意图╮
隐瞒了意图╮ 2020-12-28 20:43

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          


        
相关标签:
4条回答
  • 2020-12-28 21:24

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

    0 讨论(0)
  • 2020-12-28 21:26

    My solution:

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = false;               
    Bitmap bitmap = BitmapFactory.decodeResource(this.context.getResources(),  R.drawable.image, options );
    
    0 讨论(0)
  • 2020-12-28 21:31

    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

    0 讨论(0)
  • 2020-12-28 21:38

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

    0 讨论(0)
提交回复
热议问题