2014-02-11 58 views
1

如何将我的网格完整网格视图项目保存在一个图像中查看某人帮助我。在下面的代码,这是我的网格视图ImageAdapter这里是位是我的gridview的项目和我要救我的SD卡“mthum”位图阵列中的图像视图我想将我的GridView保存在一个图像视图中

  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; 
      } 

}

回答

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 

否则,如果你想从你的“适配器”的所有图片,你可以构建你像位图描述了这样的回答:

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

编辑:我没有看到你想保存在SD卡上的图像,有很多关于这个问题的答案,所以你应该在他们一起来看看:

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

+0

我申请此代码,它的运行宁成功感谢帮助我.. –

+0

这是运行我在我的活动中使用此代码感谢 –

+0

请标记为已回答。检查我答案左上角的标记。 – Andros

相关问题