0

我的程序有两个问题: 1.拍照后,onActivityResult()是这样的:

        pictureTaken = (Bitmap) data.getExtras().get("data");
        ImageView im = (ImageView) findViewById(R.id.view);
        im.setImageBitmap(pictureTaken);

这仅显示缩略图(显示时质量差),当我将其保存到 SD 卡时,它也是一个小图像。我需要的是以全分辨率/质量保存/显示它。我要改变什么来实现这一目标?

  1. 检索和显示用户选择的图像工作:

    selectedImage = data.getData();
    ImageView im = (ImageView) findViewById(R.id.view);
    im.setImageURI(selectedImage);
    

但是当保存用户选择的图像时,它会在这里崩溃(由调试器找到):

...
File externalStorageFile = new File(dir, finalName);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
//Error
resourceImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
byte b[] = bytes.toByteArray();
try {
...

此外,位图是您在 Android 中保存图像的唯一方法吗?

4

2 回答 2

0

检查此链接以获取示例。如果从图库中选择的图像显示位图超出范围异常,您需要解码图像。

将图像缩放到屏幕大小....

从图库中挑选图像并对其进行解码.......

于 2011-06-22T11:56:44.350 回答
0

For saving the image in sdcard use the below code

    String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
    File file = new File(extStorageDirectory, imagename);
    file.createNewFile();
    FileOutputStream fos = new  FileOutputStream(file);
    bm.compress(CompressFormat.JPEG, 75, fos);
    fos.flush();
    fos.close();
于 2011-06-22T11:10:13.523 回答