Question

How to save my grid full grid view items in one image view someone help me. In below code this is my ImageAdapter for grid view and here is bit is my gridview item and i want to save "mthum" bitmap array in my sdcard in image view

            public  class ImageAdapter extends BaseAdapter {
            private Context mContext;
            Bitmap bit = Bitmap.createScaledBitmap(S.Murge_Bitmap, 280,  280, false);
            public Bitmap[] mThum={bit,bit,bit,bit,bit,bit,bit,bit,bit,bit,bit,bit};
            public ImageAdapter(Context c) {
            mContext = c;
            }

            public int getCount() {
            return mThum.length;
            }

            public Object getItem(int position) {
            return mThum[position];
            }
            public long getItemId(int position) {
            return 0;
            }


            public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView;
            if (convertView == null) {   
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
            imageView.setScaleType(ImageView.ScaleType.CENTER);
            imageView.setPadding(1, 1, 1, 1);
            } else {
            imageView = (ImageView) convertView;
            }
            imageView.setImageBitmap(mThum[position]);
            return imageView;
            } 

}

Was it helpful?

Solution

You can use this solution, but I think it's gonna give you only a Bitmap of displayed images :

Bitmap b = Bitmap.createBitmap(mGridView.getDrawingCache());

if you have an issue with this and can't get a bitmap, try this :

mGridView.setDrawingCacheEnabled(true); 
// Without it the view will have a dimension of 0,0 and the bitmap will be null          
mGridView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 
            MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
mGridView.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); 

mGridView.buildDrawingCache(true);
Bitmap b = Bitmap.createBitmap(mGridView.getDrawingCache());
mGridView.setDrawingCacheEnabled(false); // clear drawing cache

otherwise, if you want all your images from your "Adapter" you can construct you Bitmap like describe in this answer :

https://stackoverflow.com/a/15152221/1686472

EDIT : I didn't see you wanted to save the image on SD card, there is plenty of answer about that so you should take a look at them :

https://stackoverflow.com/a/15662384/1686472

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top