我正在使用canvas.drawBitmap截取android屏幕并在捕获的图像(水印)上绘制另一个图像,
当我在 SD 卡上复制水印(另一个图像 - 比如说 visit.jpg)图像时,这一切都给出了正确的结果,捕获的图像的宽度为 500 像素,其中 visit.jpg 的宽度为 339 像素,
File file = new File( Environment.getExternalStorageDirectory() + "/visit.jpg");
Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
但我不想将水印图像复制到 sdcard 中,我希望 res 文件夹中的图像应该在捕获的图像上绘制,所以我使用
Bitmap visit = BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.visit);
并在画布上绘制并保存,它被保存了,但是水印图像(visit.jpg)被拉伸并且它的大小变得大于 339 像素。为什么 ?
我的代码是:
View v1 = findViewById(android.R.id.content).getRootView();
v1.setDrawingCacheEnabled(true);
Bitmap screenshot = Bitmap.createBitmap(v1.getDrawingCache());
Bitmap cropimg = Bitmap.createBitmap(screenshot, 50, 0, screenshot.getWidth()-100, 592);
v1.setDrawingCacheEnabled(false);
Bitmap Rbitmap = Bitmap.createBitmap(cropimg).copy(Config.ARGB_8888, true);
Bitmap visit = BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.visit); // image accessed from drawable
Canvas canvas = new Canvas(Rbitmap);
File file = new File( Environment.getExternalStorageDirectory() + "/visit.jpg"); // the image copied on sd card
Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
canvas.drawBitmap(visit, 0, 570, null); // if i put myBitmap instead of visit i.e. canvas.drawBitmap(myBitmap, 0, 570, null); then visit.jpg image gets draw properly with 339pixel width without strtch
canvas.save();