我创建了一个示例应用程序。使用camera捕获图像。它工作正常。捕获后我在sdcard中保存图像。我保留160x120尺寸的图像,我希望增加这个尺寸。如何使用自定义尺寸保存。我的代码是,
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 35, byteStream);
File fStorageDirectory = new File(
Environment.getExternalStorageDirectory(), SDCARD_FOLDER_NAME);
System.out.println("path of----"+fStorageDirectory);
if (!fStorageDirectory.exists())
fStorageDirectory.mkdirs();
OutputStream outStream = new FileOutputStream("/sdcard/"+ SDCARD_FOLDER_NAME + "/" + IMAGE_NAME);
outStream.write(byteStream.toByteArray());
outStream.close();
请指导我这样做。
答案 0 :(得分:4)
在OnActivityResult中尝试这个
BitmapFactory.Options bounds = new BitmapFactory.Options();
bounds.inSampleSize = 4;
Bitmap myImage = BitmapFactory.decodeFile(SD_CARD_TEMP_DIR,bounds);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
myImage.compress(CompressFormat.PNG, 100, bos);
bitmapdata = bos.toByteArray();