2013-02-21 27 views

回答

0

感谢您的回答。最后我这样做:

var imageView = FindViewById<ImageView>(Resource.Id.image); 
Bitmap bmp = ((BitmapDrawable)imageView.Drawable).Bitmap; 

ps:我有一个NullPointerException,因为imageView是在另一个视图。

1

工作你应该能够获得通过可绘制属性访问到指定的图像。在访问它之前一定要检查null。

1

这是我使用它的一个工作示例。

  view.setDrawingCacheEnabled(true); 
     view.buildDrawingCache(); 
     Bitmap save = view.getDrawingCache(); 

其中viewImageView,如果你想保存。那么这里是我的救命方法从我的ImageView的观点,并将其保存为.PNG

void Save() { 
    if (null != view.getDrawable()) { 
     view.setDrawingCacheEnabled(true); 
     view.buildDrawingCache(); 
     save = view.getDrawingCache(); 
     final File myDir = new File(folder); 
     myDir.mkdirs(); 
     final Random generator = new Random(); 
     int n = 10000; 
     n = generator.nextInt(n); 
     final String fname = "StyleMe-" + n + ".png"; 
      file = new File(myDir, fname); 
     if (file.exists()) 
      file.delete(); 
     try { 
      final FileOutputStream out = new FileOutputStream(file); 
      save.compress(Bitmap.CompressFormat.PNG, 100, out); 
      out.flush(); 
      out.close(); 
      sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, 
        Uri.parse("file://" 
          + Environment.getExternalStorageDirectory()))); 
      Toast.makeText(getApplication(), "Image Saved", 
        Toast.LENGTH_SHORT).show(); 
     } catch (final Exception e) { 
      Toast.makeText(getApplication(), 
        "Something Went Wrong check if you have Enough Memory", 
        Toast.LENGTH_LONG).show(); 
     } 
    } else { 
     final Toast tst = Toast.makeText(getApplication(), 
       "Please Select An Image First", Toast.LENGTH_LONG); 
     tst.setGravity(Gravity.CENTER, 0, 0); 
     tst.show(); 
    } 
    view.setDrawingCacheEnabled(false); 
} 

,这里是我的变量。

 String folder = "/sdcard/Pictures/StyleMe"; 
     static File file;