问题描述
什么是调整位图的最好方法?
使用
options.inSampleSize = 2;
点阵位图= BitmapFactory.de codeResource(getResources(),R.drawable.mandy_moore,期权);
或
位图resizedbitmap = Bitmap.createScaledBitmap(位图,200,200,真正的);
这取决于你所需要的灵活性:
options.inSampleSize = N;
意味着你将获得的图像比原来小N倍。基本上,德codeR会读1像素每N个像素。
使用该选项,如果你并不需要为您的位图特定大小,但你需要使它更小,以使用较少的内存。这对于阅读大图特别有用。
Bitmap.createScaledBitmap
从另一方面给你更多的控制:您可以指示$ P $位图pcisely的最终尺寸,...
,最好是同时使用方法的组合:
- 确定
inSampleSize
的最大值,你可以用它来有效地去$ C C的源图像$(使得德codeD映像仍比大你需要的最终尺寸) - 使用
Bitmap.createScaledBitmap
来precisely控制所产生的尺寸
What is the best way of resizing a bitmap?
Using
options.inSampleSize = 2;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.mandy_moore, options);
or
Bitmap resizedbitmap = Bitmap.createScaledBitmap(bitmap, 200, 200, true);
It depends the flexibility you need:
options.inSampleSize = N;
means that you will obtain an image which is N times smaller than the original. Basically, the decoder will read 1 pixel every N pixel.
Use that option if you don't need a particular size for your bitmap but you need to make it smaller in order to use less memory. This is particularly useful for reading big images.
Bitmap.createScaledBitmap
on the other hand give you more control: you can indicate precisely the final dimension of the bitmap, ...
The best is to use a combination of both method:
- Determine the maximal value of
inSampleSize
you can use to decode the source image efficiently (such that the decoded image is still bigger than the final size you need) - Use
Bitmap.createScaledBitmap
to precisely control the resulting size
这篇关于Android的位图大小调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!