Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Dec 30th, 2012  |  syntax: None  |  size: 1.87 KB  |  views: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. @Override
  2. protected void onDestroy() {
  3.     super.onDestroy();
  4.  
  5.     unbindDrawables(mView);
  6.     System.gc();
  7. }
  8.  
  9. private void unbindDrawables(View view) {
  10.     if (view.getBackground() != null) {
  11.         view.getBackground().setCallback(null);
  12.     }
  13.     if (view instanceof ViewGroup) {
  14.         for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
  15.             unbindDrawables(((ViewGroup) view).getChildAt(i));
  16.         }
  17.         ((ViewGroup) view).removeAllViews();
  18.     }
  19. }
  20.        
  21. BitmapDrawable bitmapDrawable = (BitmapDrawable) ctx.getResources().getDrawable(R.drawable.bg2);
  22. BitmapFactory.Options bitopt = new BitmapFactory.Options();
  23. bitopt.inSampleSize = 10;
  24. plot.setBackgroundImage(bitmapDrawable); //plot is PiePlot object
  25.        
  26. public static Bitmap decodeFile(File f,int WIDTH,int HIGHT){
  27.      try {
  28.          //Decode image size
  29.          BitmapFactory.Options o = new BitmapFactory.Options();
  30.          o.inJustDecodeBounds = true;
  31.          BitmapFactory.decodeStream(new FileInputStream(f),null,o);
  32.  
  33.          //The new size we want to scale to
  34.          final int REQUIRED_WIDTH=WIDTH;
  35.          final int REQUIRED_HIGHT=HIGHT;
  36.          //Find the correct scale value. It should be the power of 2.
  37.          int scale=1;
  38.          while(o.outWidth/scale/2>=REQUIRED_WIDTH && o.outHeight/scale/2>=REQUIRED_HIGHT)
  39.              scale*=2;
  40.  
  41.          //Decode with inSampleSize
  42.          BitmapFactory.Options o2 = new BitmapFactory.Options();
  43.          o2.inSampleSize=scale;
  44.          return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
  45.      } catch (FileNotFoundException e) {}
  46.      return null;
  47.  }
  48.        
  49. public static Bitmap getImage(byte[] image) {
  50.         BitmapFactory.Options config = new BitmapFactory.Options();
  51.         config.inPreferredConfig = Bitmap.Config.RGB_565;
  52.         config.inSampleSize = 4;
  53.         return BitmapFactory.decodeByteArray(image, 0, image.length,config);
  54.  
  55.     }
clone this paste RAW Paste Data