下面的代码定义我的位图:将缩放的位图绘制到画布上?
Resources res = context.getResources();
mBackground = BitmapFactory.decodeResource(res,
R.drawable.bg2);
//scale bitmap
int h = 800; // height in pixels
int w = 480; // width in pixels
Bitmap scaled = Bitmap.createScaledBitmap(mBackground, w, h, true); // Make sure w and h are in the correct order
...而下面的代码被用于执行/绘制(未缩放的位图):
c.drawBitmap(mBackground, 0, 0, null);
我的问题是,我怎么可能将其设置为绘制以“位图缩放”形式返回的缩放位图,而不是原始图片?
你的答案对我有效,但在参数中从宽度和高度减去1后,在显示的位图的右侧和底部显示一行(从背景中的另一个位图),删除-1工作正常。 – akshay7692
我知道这是一个较旧的帖子。但对于Android 7.0+,在分屏模式下,您可能无法依赖完整的显示宽度/高度。因此,对于使用此解决方案的任何人,您应该牢记这一点。 – MCLLC
会以这种方式绘制位图很慢吗? – Amos