图片Android的缩放屏幕像素密度

问题描述:

我在71,12像素的嵌入式绘制48×48像素的应用程序/英寸 我通过流加载相同的图像到网络服务器,然后加载流

I have an application with an embedded drawable 48x48 pixel at 71,12 pixels/inch I load the same image via a stream to a webserver, then load that stream

return new BitmapDrawable(getActivity().getResources(), new ByteArrayInputStream(imageThumbnail));

显示的结果是: http://imgur.com/3NO47

我怎样才能获得BitmapDrawable规模一样的可绘制的休息吗?

How can i get the BitmapDrawable to scale the same as the rest of the drawables?

做这样的事情:

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

Bitmap bitmapOrg = new BitmapDrawable(getResources(), new  ByteArrayInputStream(imageThumbnail)).getBitmap();

int width = bitmapOrg.getWidth();
int height = bitmapOrg.getHeight();

float scaleWidth = metrics.scaledDensity;
float scaleHeight = metrics.scaledDensity;

// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);

// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true);

也许尝试了目前存在的方法...尝试设置的高度和宽度在逢低XML布局图像,我猜你有目前WRAP_CONTENT高度和宽度ImageView的话,尝试设置高度和宽度48dip

Maybe try a differnet approach... try setting the height and width of images in the XML layout in dips, I am guessing you have the ImageView with wrap_content height and width at the moment, try setting the height and width to 48dip