我正在构建一个用相机拍照的应用程序,然后在实际图像中添加一些文字。因此,我可以共享图像,它将嵌入文本。我尝试了很多不同的方法,但都没有。以下是我最近的尝试,即保存图像,但没有嵌入文本。必须有一个更优雅的方法,而不是创建位图,画布上绘制,然后将其转换为输出流只是为了保存它。花了太长时间(几天)搜索教程并将他们的点点滴滴混在一起后,有没有人有任何建议来操纵捕获的图像并将其保存到SD卡?我应该保存图像,然后读取并操作它,或者在保存之前操作它吗?
private PictureCallback mPicture = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
Bitmap photo = BitmapFactory.decodeByteArray(data, 0, data.length).copy(Config.RGB_565, true);
Canvas canvasView = new Canvas(photo);
Paint paint = new Paint();
paint.setTextSize(52);
paint.setColor(Color.GREEN);
canvasView.drawText("Test Text To Add", 0, 0, paint);
File pictureFile = getOutputMediaFile();
if (pictureFile == null){
Log.d(logTag, "Error creating media file, check storage permissions");
releaseCamera();
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
photo.compress(CompressFormat.PNG,100, bos);
byte[] bitmapdata = bos.toByteArray();
fos.write(bitmapdata);
fos.close();
releaseCamera();
} catch (FileNotFoundException e) {
Log.d(logTag, "File not found: " + e.getMessage());
releaseCamera();
} catch (IOException e) {
Log.d(logTag, e.toString());
releaseCamera();
}
}
};