在 SD 卡的图像视图中显示高清图像



我只是制作一个简单的程序,显示手机SD卡中的高清图像。我的代码是这样的

    ImageView iv=(ImageView)findViewById(R.id.imageView1);
    File f = new File("/sdcard/mytestdownloadedfile2.jpg");
    Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath());
    iv.setImageBitmap(bmp);

当我运行我的代码时,它不显示任何图像,而是当我将此高清照片更改为标准照片或 PNG 时。它毫无问题地显示它。所以请帮助我。

尝试使用此方法解码文件,让我知道它是否有效

public static Bitmap decodeScaledBitmapFromSdCard(String filePath,
        int reqWidth, int reqHeight) {
    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(filePath, options);
    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeFile(filePath, options);
}

最新更新