and*_*vid 11 io camera android image file
我刚刚完成了我的相机活动,它可以很好地保存数据.拍摄照片后我做了什么:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
我想要的是已经在上面的代码中给出的评论.我不希望将图像保存到文件中,但要旋转然后保存!谢谢!
// 编辑:我目前正在做什么(工作但仍会遇到大图像的内存问题)
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();
Run Code Online (Sandbox Code Playgroud)
May*_*ini 22
从SD卡读取路径并粘贴以下代码......旋转后将替换现有照片..
注意:Exif不适用于大多数设备,它会返回不正确的数据,因此在保存到您想要的任何程度之前硬编码旋转是好的,只需更改postRotate中的角度值即可.
String photopath = tempphoto.getPath().toString();
Bitmap bmp = BitmapFactory.decodeFile(photopath);
Matrix matrix = new Matrix();
matrix.postRotate(90);
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
FileOutputStream fOut;
try {
fOut = new FileOutputStream(tempphoto);
bmp.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
在创建之前,FileOutputStream您可以Bitmap从已使用Matrix. 为此,您可以使用以下方法:
createBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)
Run Code Online (Sandbox Code Playgroud)
其中m定义了一个将转置原始位图的矩阵。
有关如何执行此操作的示例,请查看此问题: Android:如何在中心点上旋转位图
| 归档时间: |
|
| 查看次数: |
24188 次 |
| 最近记录: |