[android-developers] recycle bitmap

2011-04-07 Thread vani reddy
Hi ,

I am gettting the following exception in log

04-07 14:06:13.759: ERROR/AndroidRuntime(3233): java.lang.OutOfMemoryError:
bitmap size exceeds VM budget
04-07 14:06:13.759: ERROR/AndroidRuntime(3233): at
android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-07 14:06:13.759: ERROR/AndroidRuntime(3233): at
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459)
04-07 14:06:13.759: ERROR/AndroidRuntime(3233): at
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:515)
04-07 14:06:13.759: ERROR/AndroidRuntime(3233): at
com.tli.bee.CoverflowExample.getBitmap(CoverflowExample.java:558)
04-07 14:06:13.759: ERROR/AndroidRuntime(3233): at
com.tli.bee.CoverflowExample.run(CoverflowExample.java:542)
04-07 14:06:13.759: ERROR/AndroidRuntime(3233): at
java.lang.Thread.run(Thread.java:1096)

How to recycle the bitmap?
-- 
 Regards,
Vani Reddy

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] recycle bitmap

2011-04-07 Thread Kostya Vasilyev

Bitmap.recycle()

http://developer.android.com/reference/android/graphics/Bitmap.html#recycle()

07.04.2011 13:21, vani reddy пишет:


Hi ,

I am gettting the following exception in log

04-07 14:06:13.759: ERROR/AndroidRuntime(3233): 
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
04-07 14:06:13.759: ERROR/AndroidRuntime(3233): at 
android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-07 14:06:13.759: ERROR/AndroidRuntime(3233): at 
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:459)
04-07 14:06:13.759: ERROR/AndroidRuntime(3233): at 
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:515)
04-07 14:06:13.759: ERROR/AndroidRuntime(3233): at 
com.tli.bee.CoverflowExample.getBitmap(CoverflowExample.java:558)
04-07 14:06:13.759: ERROR/AndroidRuntime(3233): at 
com.tli.bee.CoverflowExample.run(CoverflowExample.java:542)
04-07 14:06:13.759: ERROR/AndroidRuntime(3233): at 
java.lang.Thread.run(Thread.java:1096)


How to recycle the bitmap?
--
Regards,
Vani Reddy

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en 



--
Kostya Vasilyev -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] recycle bitmap

2011-04-07 Thread vani reddy
Hi,
I referred the below link:
http://www.memofy.com/memofy/show/1008ab7f2836ab7f01071c2dbfe138/outofmemory-exception-when-decoding-with-bitmapfactory

http://www.memofy.com/memofy/show/1008ab7f2836ab7f01071c2dbfe138/outofmemory-exception-when-decoding-with-bitmapfactorywhen
to recycle the bitmap,delow is my code:

public void getBitmap( String[] str)
{
 InputStream is =null;
try {
for(int x =0;xstr.length;x++)
{
URL myFileUrl =new URL(str[x]);
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
 is = conn.getInputStream();

 BitmapFactory.Options options = new BitmapFactory.Options();
 options.inTempStorage = new byte[16*1024];
orgImg = BitmapFactory.decodeStream(is);
al_bitmap.add(orgImg);
}
 } catch (IOException e) {
e.printStackTrace();
 }
 finally{
if(is!=null)
{
try {
is.close();
 } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
 }

public class ImageAdapter extends BaseAdapter {
 int mGalleryItemBackground;
 private Context mContext;
 private FileInputStream fis;
 private ImageView[] mImages;
 public ImageAdapter(Context c) {
  mContext = c;
  mImages = new ImageView[al_bitmap.size()];
 }
 public int getCount() {
 System.out.println(bitmap size +al_bitmap.size());
 return al_bitmap.size();
 }

 public Object getItem(int position) {
 return position;
 }

 public long getItemId(int position) {
 return position;
 }

 public View getView(int position, View convertView, ViewGroup parent) {

  //Use this code if you want to load from resources

 ImageView img;
 if (convertView == null) {
img = new ImageView(mContext);
}
 LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.coverflow, parent, false);
img = (ImageView) view.findViewById(R.id.img);
 System.out.println( albitmap +position   +position+
+al_bitmap.get(position));
if(al_bitmap.get(position) ==null)
{
img.setImageResource(R.drawable.bee);
 img.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
 TextView title = (TextView) view.findViewById(R.id.title);
title.setText(titles.get(position));
TextView descrition = (TextView) view.findViewById(R.id.description);
descrition.setText(subtitle.get(position));
 BitmapDrawable drawable = (BitmapDrawable) img.getDrawable();
 drawable.setAntiAlias(true);
}
else
{
   img.setImageBitmap(al_bitmap.get(position));
img.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
TextView title = (TextView) view.findViewById(R.id.title);
title.setText(titles.get(position));
TextView descrition = (TextView) view.findViewById(R.id.description);
descrition.setText(subtitle.get(position));
 BitmapDrawable drawable = (BitmapDrawable) img.getDrawable();
 drawable.setAntiAlias(true);
}
 return view;
 }

Please reply




-- 
 Regards,
Vani Reddy

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en