Visualizzazione stampabile
-
image view
Vorrei visionare una immagine jpg con imageview in android studio. Sto usando:
File imgFile = new File("/storage/emulated/0/carte/b03.jpf;
Bitmap myBitmap = BitmapFactory.DecodeFile(imgFile.getAbsolutePath() :
risultato:imgFile esiste, ma myBitmap = null senza sollevare nessuna eccezione
Qualche suggerimento ? Grazie
-
protected void onCreate(Bundle savedInstanceState) { //on create
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button vbtn1=(Button)findViewById(R.id.btn1);
vbtn1.setBackgroundResource(android.R.color.holo_g reen_light);
vbtn1.setFocusableInTouchMode(true);
// vbtn1.requestFocus(); //cambio colore e fuoco su modifica
//?????????????????????????????????????????????????? ????????????????????????????
File imgFile=new File("/storage/emulated/0/carte/b03.jpg");
if(imgFile.exists()) {
BitmapFactory.Options bitopt=new BitmapFactory.Options();
bitopt.inJustDecodeBounds=true;
bitopt.inSampleSize=1;
try {
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath() , bitopt);
ImageView myImage = (ImageView) findViewById(R.id.imageView);
myImage.setImageBitmap(myBitmap);
if (myBitmap == null) {
TextView tvb = (TextView) findViewById(R.id.tv2);
tvb.setText("no bitmap");
} else {
myImage.setImageBitmap(myBitmap);
}
}catch (Exception e) {
System.out.println("Error " + e.getMessage());
}
}
else{
TextView tvb = (TextView)findViewById(R.id.tv2);
tvb.setText("il file non esiste");
}
La domanda è sempre la stessa: myBitmap è nullo e non viene soolevata nessuna eccezionre