问题
I have some problem show images from sd card, i try to load bitmap into imageview.
This is the code to load image:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
File imagen1 = new File(ruta + contratoActual.getImgDoc1());
if (imagen1.exists()) {
try {
bmap = BitmapFactory.decodeStream(new FileInputStream(imagen1), null, options);
ByteArrayOutputStream out = new ByteArrayOutputStream();
bmap.compress(Bitmap.CompressFormat.PNG, 100, out);
decoded[0] = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));
} catch (FileNotFoundException e) {
Log.e("ERROR", e.getMessage());
}
load bitmap into image view:
LayoutParams p = (LayoutParams) img1.getLayoutParams();
p.width = 250;
p.height = 190;
if (result[0] != null) {
img1.setImageBitmap(result[0]);
img1.setScaleType(ImageView.ScaleType.CENTER_CROP);
img1.setLayoutParams(p);
result[0].recycle();
}
and here show the result:
and i have this log result:
回答1:
Try this inside your code:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap YourBitmap = BitmapFactory.decodeFile(YourImagePath, options);
Example
File Read Permission:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
来源:https://stackoverflow.com/questions/24246972/load-bitmap-from-sd-card-dont-work