0
當我用我的Android相機拍照時,我的屏幕上有一張圖像(imageview3
),我想用我的照片保存。Android:用照片上的圖像保存照片
這裏是我的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卡上的文件(即從文件輸出流中的畫布上寫入數據)
你知道如何將Canvas保存到我的SD卡中的JPEG中,即如何從文件輸出流的畫布寫入數據? – morg
好了,謝謝http://www.jondev.net/articles/Combining_2_Images_in_Android_using_Canvas 重要的是我們必須保存「cs」而不是畫布(請參閱鏈接) – morg