我的应用程序有一个“大头”功能,可让用户在拍照与摄像头,并同时显示在相机视图上重叠图像。拍完照片后,我需要保存用户在拍摄照片到文件系统时看到的内容。用相机保存图像叠加拍摄的图像underneith
我曾经历过1度大的问题,而开发的解决方案是:捕捉与兼容的尺寸,我可以覆盖图像附加到产生,而拍照什么的用户看到的图像。
我似乎无法从相机定义尺寸(我必须从基本上它们的列表中选择)拍摄的图像。有些手机只能产生一定的尺寸。
既然不能选择捕捉图像的大小,看起来好像我将需要包括叠加图像的许多不同的尺寸,并附加了最佳匹配所拍摄的图像。我不能在摄像机图像上拍摄任何旧的覆盖图,并使其看起来正确。
问题:
- 我是过于复杂这个“摄像机图像+覆盖图像创造”的过程?
- 你有什么样的建议来完成这项任务,而不需要包括几个不同尺寸的覆盖图像?
编辑: 这是我的解决方案(简要)。请意识到这不是一个完美的,也许不是最有效的方式来做到这一点,但它的工作原理。有些东西可能是不必要的/多余的,但无论如何
注:
- 这不起作用太大的平板设备。
- 覆盖图像需要被旋转到横向模式(即使你将采取的图像保存在手机中的纵向)
- 覆盖规模小480x320
- 需要强制活动为横向模式,而拍摄照片(现已覆盖看起来像它的画像!)
- 我添加使用
addContentView(overlayImageView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
...叠加图像视图
final Camera.PictureCallback jpegCallback = new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
BitmapFactory.Options options = new BitmapFactory.Options();
Bitmap mutableBitmap = null;
try {
//for a PORTRAIT overlay and taking the image holding the phone in PORTRAIT mode
mutableBitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options).copy(Bitmap.Config.RGB_565, true);
Matrix matrix = new Matrix();
int width = mutableBitmap.getWidth();
int height = mutableBitmap.getHeight();
int newWidth = overlayImage.getDrawable().getBounds().width();
int newHeight = overlayImage.getDrawable().getBounds().height();
float scaleWidth = ((float) newWidth)/width;
float scaleHeight = ((float) newHeight)/height;
matrix.postScale(scaleWidth, scaleHeight);
matrix.postRotate(90);
Bitmap resizedBitmap = Bitmap.createBitmap(mutableBitmap, 0, 0, mutableBitmap.getWidth(), mutableBitmap.getHeight(), matrix, true);
finalBitmap = resizedBitmap.copy(Bitmap.Config.RGB_565, true);
Canvas canvas = new Canvas(finalBitmap);
Bitmap overlayBitmap = BitmapFactory.decodeResource(getResources(), overlay);
matrix = new Matrix();
matrix.postRotate(90);
Bitmap resizedOverlay = Bitmap.createBitmap(overlayBitmap, 0, 0, overlayBitmap.getWidth(), overlayBitmap.getHeight(), matrix, true);
canvas.drawBitmap(resizedOverlay, 0, 0, new Paint());
canvas.scale(50, 0);
canvas.save();
//finalBitmap is the image with the overlay on it
}
catch(OutOfMemoryError e) {
//fail
}
}
}
嗨,binnyb! 现在有类似的问题。 你能帮我吗? 你能显示你的代码吗? 谢谢! – vsvydenko 2012-01-04 19:50:43