我需要从相机中获取图像并将其保存在另一个图像中。我怎样才能做到这一点?然后我想将这个新图像保存在 SD 卡上。
问问题
1388 次
1 回答
1
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);
}
}
于 2012-08-07T16:50:27.597 回答