【发布时间】:2012-03-25 06:00:42
【问题描述】:
我刚刚完成了我的相机活动,它可以很好地保存数据。 拍完照片后我会做什么:
protected void savePictureData() {
try {
FileOutputStream fs = new FileOutputStream(this.photo);
fs.write(this.lastCamData);
fs.close(); //okay, wonderful! file is just written to the sdcard
//---------------------
//---------------------
//TODO in here: dont save just the file but ROTATE the image and then save it!
//---------------------
//---------------------
Intent data = new Intent(); //just a simple intent returning some data...
data.putExtra("picture_name", this.fname);
data.putExtra("byte_data", this.lastCamData);
this.setResult(SAVED_TOOK_PICTURE, data);
this.finish();
} catch (IOException e) {
e.printStackTrace();
this.IOError();
}
}
我想要的已经是上面代码中给出的注释。我不希望图像只是保存到文件中,而是要旋转然后保存!谢谢!
//编辑:我目前在做什么(工作但仍然遇到大图像的内存问题)
byte[] pictureBytes;
Bitmap thePicture = BitmapFactory.decodeByteArray(this.lastCamData, 0, this.lastCamData.length);
Matrix m = new Matrix();
m.postRotate(90);
thePicture = Bitmap.createBitmap(thePicture, 0, 0, thePicture.getWidth(), thePicture.getHeight(), m, true);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
thePicture.compress(CompressFormat.JPEG, 100, bos);
pictureBytes = bos.toByteArray();
FileOutputStream fs = new FileOutputStream(this.photo);
fs.write(pictureBytes);
fs.close();
Intent data = new Intent();
data.putExtra("picture_name", this.fname);
data.putExtra("byte_data", pictureBytes);
this.setResult(SAVED_TOOK_PICTURE, data);
this.finish();
【问题讨论】:
-
不,不是真的,更多的是关于如何旋转和保存之后
-
好吧,我的解决方案似乎有效 - 清理了项目...
-
那么哪一个正在工作,有问题的编辑或接受的答案建议?
-
当有足够的可用内存时编辑工作(正常情况应该是什么);)
标签: android image file io camera