我刚完成我的相机活动,它很奇妙地保存数据。 我做什么拍摄照片后:Android在保存前旋转图片
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();
的可能重复[安卓:如何在一个中心点旋转一个位图(http://stackoverflow.com/questions/4166917/android-how-to-rotate-a-bitmap-on-a - 中心点) – slayton 2012-03-07 17:21:10
不,真的,它更多关于如何旋转和保存之后 – androidavid 2012-03-07 17:49:00
好吧我的解决方案似乎工作 - 清理项目... – androidavid 2012-03-07 23:24:25