Image, Web, Remote, URL, URLConnection, BitmapFactory

Quickly share your Android Code Snippets here...

Re: Image, Web, Remote, URL, URLConnection, BitmapFactory

Postby Stageline » Mon Aug 22, 2011 5:33 pm

Hy gurus!

How to use this ??

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package hu.mouseoleum;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.IOException;
  5. import java.net.URL;
  6. import java.net.URLConnection;
  7.  
  8. import android.app.Activity;
  9. import android.graphics.Bitmap;
  10. import android.graphics.BitmapFactory;
  11. import android.os.Bundle;
  12. import android.util.Log;
  13.  
  14. public class Programok extends Activity
  15. {
  16.         URL url;
  17.         @Override
  18.         protected void onCreate(Bundle savedInstanceState)
  19.         {
  20.                 super.onCreate(savedInstanceState);
  21.                 setContentView(R.layout.main);
  22.                 url.getRemoteImage("http://mouseoleum.hu/img/programbanner.jpg");
  23.         }
  24.         public Bitmap getRemoteImage(final URL aURL) {
  25.                 try {
  26.                         final URLConnection conn = aURL.openConnection();
  27.                         conn.connect();
  28.                         final BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
  29.                         final Bitmap bm = BitmapFactory.decodeStream(bis);
  30.                         bis.close();
  31.                         return bm;
  32.                 } catch (IOException e) {
  33.                         Log.d("DEBUGTAG", "Oh noooz an error...");
  34.                 }
  35.                 return null;
  36.         }
  37. }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
Stageline
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Aug 22, 2011 5:28 pm

Top
Previous

Return to Code Snippets for Android

Who is online

Users browsing this forum: Yahoo [Bot] and 6 guests