Reputation: 6970
I need to get an image from the camera and save it in over another image. How can I do this? Then I want to save this new image on the SD card.
Upvotes: 0
Views: 1429
Reputation: 9599
1) Here's a tutorial how to use the android's camera: tutorial
2) To overlay the cameras image over a bitmap you'll have to: - Create a bitmap - Create a canvas with a reference to that bitmap - Draw the picture from the camera to the canvas. (Since you are not making a copy of this bitmap when using the canvas, the changes will apply to the bitmap you created).
3) To save a bitmap, you can use this method I wrote:
/**
* <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);
}
}
Upvotes: 1