我有一个相机预览层。最重要的是,我正在移动(拖放)并在我的应用程序中缩放透明的小图像。在那里我使用 png 的图像视图并使用矩阵进行缩放。在将imageview缩放并定位到我想要的位置后,我需要一张图片,其背景来自相机预览,前景具有imageview的缩放和移动位置。
去做这个,
我正在通过相机拍摄图像。
然后我在从相机捕获的图像上绘制图像视图中的图像。
我尝试使用以下代码,但效果不佳。
private PictureCallback mPicture = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
if (pictureFile == null){
Log.d("1", "Error creating media file, check storage permissions: ");
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
//captured=pictureFile.getAbsoluteFile();
picturefilepath=pictureFile.getPath();
ImageView imgv= (ImageView) findViewById(R.id.midimage);
//Matrix ms=imgv.getImageMatrix();
Bitmap b=overlay(BitmapFactory.decodeFile(pictureFile.getPath()), imgv);
ImageView capturedset= (ImageView) findViewById(R.id.capturedimage);
capturedset.setImageBitmap(b);
} catch (FileNotFoundException e) {
Log.d("2", "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d("3", "Error accessing file: " + e.getMessage());
}
}
};
private Bitmap overlay(Bitmap bmp2, ImageView view) {
Bitmap bmOverlay = Bitmap.createBitmap(bmp2.getWidth(), bmp2.getHeight(), bmp2.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp2, canvas.getMatrix(), null);
view.draw(canvas);
return bmOverlay;
}