Android 安卓:用照片上的图像保存照片
当我用安卓相机拍照时,屏幕上有一个图像(Android 安卓:用照片上的图像保存照片,android,camera,image,Android,Camera,Image,当我用安卓相机拍照时,屏幕上有一个图像(imageview3),我想与我的照片一起保存 这是我的onPictureTaken方法 public void onPictureTaken(byte[] data, Camera camera) { File imagesFolder = new File(Environment.getExternalStorageDirectory(), "/Ker"); imagesFolder.mkdirs(); String fileN
imageview3
),我想与我的照片一起保存
这是我的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
。为什么没有保存真实的摄影机视图
编辑
我也在尝试帆布:
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上从画布写入数据)您正在将imageview的JPEG和相机的JPEG附加到一个文件中 为每个文件创建单独的文件输出流,并将Bitmap.compress()和onPictureTaken数据数组中的数据写入各自的流中 如果希望将两幅图像合并为一幅图像,则需要将数据数组解码为位图,然后使用画布将ImageView位图和相机捕获的位图按照所需的排列绘制到画布上,然后将其保存为单个jpeg
您不能简单地将两个压缩的JPEG比特流连接在一起;文件格式不是这样工作的。您知道如何将画布保存到SD卡中的jpeg格式(即如何将画布中的数据写入文件输出流)吗?好的,理解了,因为重要的一点是我们必须保存“cs”,而不是画布(请参阅链接)