0
我需要从相机获取图像并将其保存在另一张图像中。我怎样才能做到这一点?然后我想将这张新图像保存在SD卡上。Android:从相机在画布上保存图像
我需要从相机获取图像并将其保存在另一张图像中。我怎样才能做到这一点?然后我想将这张新图像保存在SD卡上。Android:从相机在画布上保存图像
1)这里有一个教程如何使用Android的相机: tutorial
2)覆盖了位图的摄像机图像,你必须: - 创建一个位图 - 创建一个画布参考该位图 - 将照片从相机绘制到画布。 (由于您在使用画布时未创建此位图的副本,所做更改将应用于您创建的位图)。
3)要保存一个位图,你可以用这个方法我说:
/**
* <b><i>public void writeBitmapToMemory(String filename, Bitmap bitmap)</i></b>
* <br>
* Since: API 1
* <br>
* <br>
* Write a bitmap to the phone's internal storage.
*
* @param filename
* The name of the file you wish to write to.
*
*
*/
public void writeBitmapToMemory(String filename, Bitmap bitmap) {
FileOutputStream fos;
// Use the compress method on the Bitmap object to write image to the OutputStream
try {
fos = game.openFileOutput(filename, Context.MODE_PRIVATE);
// Writing the bitmap to the output stream
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();
// this.gameEngineLog.d(classTAG, "Bitmap successfully written: " + filename);
}
catch (FileNotFoundException e) {
e.printStackTrace();
// this.gameEngineLog.d(classTAG, "Bitmap couldn't be written: " + filename);
}
catch (IOException e) {
e.printStackTrace();
this.gameEngineLog.d(classTAG, "Bitmap couldn't be written: " + filename);
}
}