Creating a bitmap from png file stored at sdcard (Android) -


I am trying to create a bitmap from a PNG file stored on an SD card and then set the bitmap in an image view . But it is not working.

Here is the code:

  import java.io.File; Import java.io.FileOutputStream; Import java.io.IOException; Import java.io.InputStream; Import java.io.OutputStream; Import java.net.MalformedURLException; Import java.net.URL; Import com.pxr.tutorial.xmltest.R; Import Android.graphics. Bitmap; Import and roid.graphics.BitmapFactory; Import android.os environment; Import android.widget.ImageView; Public class Getbackground {URL url; Public stable long download file (url url2) {url url = new url ("http://oranjelan.nl/oranjelan-bg.png"); InputStream input = url.openstream (); {{File File ONSD = Environment .getExternalStorage Directory (); String storage path = fileon.sd.etabolitepath (); OutputStream Output = New FileOperputStream (Storage Path + "/oranjelanbg.png"); Try {byte [] buffer = new byte [1024]; Int BitesRad = 0; While ((BytesRed = InputRead (buffer, 0, buffer.lamp)) gt; = 0) {output.write (buffer, 0, bytes read); }} Finally {output.flush (); Output.close (); // ------------------------------------------------ -------------------------------------------------- -------- Bitmap BckGrnd = BitmapFactory.decodeFile (Storage Path + "/oranjelanbg.png"); Image view background = (image view) Find VVBIID (RID imageVi1); BackGround.setImageBitmap (BckGrnd); // ------------------------------------------------ ---------- = --------------------------------------- --------}} Catch (IOE EXPRESS E) {New Runtime Expansion (E); } Finally {try} {input.close ()}} hold (IOException e) {new runtime exception (e); }}}} Grip (Malarmdoor prefix) {new runtime exposure (ex); } Hold (IOException E) {new runtime exception (E); } Return 0; } // ----------------------------------------------- ------------------------------------------ Personal Static ImageView Search ViewById (int imageview1 ) {// TODO tap auto-generated method stub returns; } // ----------------------------------------------- ------------------------------------------}  > 

You can not .. Image View Background = (Image View) Find VVBIID (RID.miment VI1); BackGround.setImageBitmap (BckGrnd);

How can you get a reference to ImageView in non-activity class Getbackground ?

You can only update the UI component in the menu thread and if its non-activity is in the classroom then using context (context) of that calling activity class.

Then complete this code in your activity class after the Getbackground is completed.

Comments