我使用以下代码
在sdcard中保存捕获的图像class SavePhotoTask extends AsyncTask<byte[], String, String> {
@Override
protected String doInBackground(byte[]... jpeg) {
File photo=new File(Environment.getExternalStorageDirectory(),"photo.jpg");
if (photo.exists()) {
photo.delete();
}
try {
FileOutputStream fos=new FileOutputStream(photo.getPath());
fos.write(jpeg[0]);
fos.close();
}
catch (java.io.IOException e) {
Log.e("PictureDemo", "Exception in photoCallback", e);
}
return(null);
}
}
但是我得到分辨率为1024 * 768的图像如何更改该图像的重新生成。
我正在调用SavePhotoTask,就像这样
Camera.PictureCallback photoCallback=new Camera.PictureCallback(){
public void onPictureTaken(byte[] data, Camera camera){
bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
Bitmap mutableBitmap = bmp.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas(mutableBitmap);
canvas.drawBitmap(itembmp,left,right,null);
image.setImageBitmap(mutableBitmap);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
mutableBitmap.compress(Bitmap.CompressFormat.PNG,100, stream);
byte[] byteArray = stream.toByteArray();
new SavePhotoTask().execute(byteArray);
Toast.makeText(PreviewDemo1.this,"Image Saved",Toast.LENGTH_LONG).show();
camera.startPreview();
inPreview=true;
}
};
提前致谢
答案 0 :(得分:0)
传递给已经具有该解决方案的doInBackground
方法的jpeg - 您需要更改调用此代码的任何内容。
答案 1 :(得分:0)
如果您可以将其解析为BitMap,那么您可以使用它:
private final int MAX_WIDTH = 400;
private final int MAX_HEIGHT = 400;
public Bitmap getResizedBitmap(Bitmap bm) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth;
float scaleHeight;
if (width < MAX_WIDTH && height < MAX_HEIGHT) {
return bm;
}
if (width > height) {
scaleWidth = ((float) MAX_WIDTH) / width;
scaleHeight = ((float) MAX_HEIGHT * height / width) / height;
} else {
scaleWidth = ((float) MAX_WIDTH * width / height) / width;
scaleHeight = ((float) MAX_HEIGHT) / height;
}
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height,
matrix, false);
return resizedBitmap;
}