安卓:保存的照片与照片图像 [英] Android: Saving photo with image on photo
问题描述
当我带着我的Android相机拍摄照片,有一个形象( imageview3
)我的屏幕我要救我的照片上。
When I take a picture with my Android camera, there is an image (imageview3
) on my screen that I want to save with my picture.
下面是我的 onPictureTaken
法
public void onPictureTaken(byte[] data, Camera camera) {
File imagesFolder = new File(Environment.getExternalStorageDirectory(), "/Ker");
imagesFolder.mkdirs();
String fileName = "Ker_.jpg";
output = new File(imagesFolder, fileName);
ImageView view = (ImageView) gameactivity.findViewById(R.id.imageView3);
view.setDrawingCacheEnabled(true);
Bitmap b = view.getDrawingCache();
FileOutputStream fos = null;
try {
fos = new FileOutputStream(output);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
b.compress(CompressFormat.JPEG, 95, fos);
try {
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
camera.stopPreview();
}
当我打开文件夹,保存的图片仅仅是 imageview3
黑色背景。为什么真正的摄像机视图没有保存?
When I open the folder, the picture saved is only the imageview3
with a black background. Why has the real camera view not been saved?
修改
我试图用帆布的东西太多:
EDIT I'm trying something with canvas too:
output = new File(imagesFolder, fileName);
ImageView view = (ImageView) gameactivity.findViewById(R.id.imageView3);
view.setDrawingCacheEnabled(true);
Bitmap b = view.getDrawingCache();
FileOutputStream fos = null;
try {
fos = new FileOutputStream(output);
fos.write(data);
fos.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
FileOutputStream fos2 = null;
b.compress(CompressFormat.JPEG, 95, fos2);
try {
Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fos.getFD());
Bitmap bitmap2 = BitmapFactory.decodeFileDescriptor(fos2.getFD());
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(bitmap2, null, null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
这是否正确?如何在画布保存到我的SD卡一个文件(即写从FileOutputStream中画布上的数据)
Is that correct? How to save the canvas into a file on my sdcard (ie write data from canvas on fileoutputstream)
推荐答案
你追加的ImageView从相机的JPEG和JPEG将成为一个单一的文件。
You're appending the JPEG of the imageview and the JPEG from the camera into a single file.
创建为每个文件一个单独的文件输出流,并从Bitmap.com preSS()中的数据和onPictureTaken数据阵列写入到自己的数据流。
Create a separate file output stream for each file, and write the data from Bitmap.compress() and the onPictureTaken data array into their own streams.
如果您想将两个图像组合成一个单一的形象,你需要去code中的数据阵列成位图,然后用画布绘制ImageView的位图和摄像机捕获的位图在上你想要的,然后安排帆布出保存为单个JPEG。
If you want the two images to be combined into a single image, you'll need to decode the data array into a Bitmap, and then use a Canvas to draw the ImageView bitmap and the camera-captured Bitmap onto the canvas in the arrangement you want, and then save that out as a single jpeg.
您不能简单地连接两个COM pressed JPEG比特流在一起;该文件格式不这样的。
You can't simply concatenate two compressed JPEG bitstreams together; the file format doesn't work that way.
这篇关于安卓:保存的照片与照片图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!