BitmapFactory返回比源更大的图像 [英] BitmapFactory returns bigger image than source

查看:87
本文介绍了BitmapFactory返回比源更大的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我是来自一个名为png图片创建位图 image.png 。该图像具有尺寸75(宽)×92(高)。当我运行此code:

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

和屏幕上的图像比具有尺寸为75×92。我能做些什么来让Android负载与正确尺寸的形象呢?

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?

推荐答案

这听起来像您的设备上的屏幕像素密度比image.png其中创建密度不同。

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

如果你真的想prevent缩放,你可以尝试以下操作之一:

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

  1. 放入水库图像/绘制-nodpi(http://developer.android.com/guide/practices/screens_support.html#qualifiers)

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

使用ImageView.ScaleType.CENTER(http://developer.android.com/reference/android/widget/ImageView.ScaleType.html)

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

刚刚发现此相关的问题上这样:<一href="http://stackoverflow.com/questions/4091921/android-how-to-stop-android-1-6-from-scaling-images">Android:如何从缩放图像

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

这篇关于BitmapFactory返回比源更大的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆