【发布时间】:2014-09-14 00:27:13
【问题描述】:
我有两个想要实现的目标。
- 按比例缩放位图。
- 缩放相同的位图,使其高度等于设备的高度。
尝试此操作时,我发现在像素较少的设备上,缩放工作正常,但在像素较多的设备上,缩放会强制位图达到 4096x4096 像素限制:
W/OpenGLRenderer(10630): Bitmap too large to be uploaded into a texture (4476x885, max=4096x4096)
到目前为止,我正在使用 Bitmap.createBitmap(Bitmap source, int x, int y, int width, int height) 来缩放我的位图:
float conversion = (float) view.getHeight() / (float) originalBitmap.getHeight();
Matrix mat = new Matrix();
mat.postScale(conversion,conversion);
Bitmap resizedBitmap =
Bitmap.createBitmap(originalBitmap,0,0,originalBitmap.getWidth(),
originalBitmap.getHeight(), mat, false);
imageView.setImageBitmap(resize);
上面的代码加上下面的 xml 允许位图缩放整个屏幕:
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:scaleType="matrix"/>
如果有任何其他方法可以将位图按比例缩放到整个屏幕,我将非常感谢这些建议。
【问题讨论】:
标签: android matrix bitmap scale fullscreen