如何在一个图像视图中保存我的网格完整网格视图项有人帮助我。在下面的代码中,这是我的ImageAdapter用于网格视图,这里是bit是我的gridview项目,我想在图片视图中的sdcard中保存“mthum”位图数组
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;
}
}
答案 0 :(得分:4)
您可以使用此解决方案,但我认为它只会为您提供显示图像的位图:
Bitmap b = Bitmap.createBitmap(mGridView.getDrawingCache());
如果您遇到此问题并且无法获取位图,请尝试以下操作:
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
否则,如果你想要你的“适配器”中的所有图像,你可以在这个答案中构建像Bitmap一样的位图:
https://stackoverflow.com/a/15152221/1686472
编辑:我没有看到你想将图像保存在SD卡上,有很多答案,所以你应该看看它们: