2011-01-24 48 views
2

我有一個ImageView的。如何將imageview的位圖圖像轉換成機器人

LoaderImageView image=new LoaderImageView(context,path1); 
在上面的語句

它返回一個imageview.So我想將它轉換成一個bitmap.so請告訴我如何imageview的轉換成位圖圖像。

ImageView i=new ImageView(context); 
    i.setImageBitmap(convertimagetobitmap); 

在上述聲明中,我已將位圖圖像(轉換後的圖像)設置爲另一個imageview。

在此先感謝。

問候

+0

我不知道你想要做什麼。 : - ? –

+0

我想要做的設置在GridView的 – Ramakrishna

+0

是什麼LoaderImageView的形象呢?它是類擴展imageview的OT其他?.PLS描述 –

回答

6

拿來看這段代碼:


Bitmap viewBitmap = Bitmap.createBitmap(i.getWidth(),i.getHeight(),Bitmap.Config.ARGB_8888);//i is imageview whch u want to convert in bitmap 
Canvas canvas = new Canvas(viewBitmap); 

i.draw(canvas); 

完蛋了您的ImageView存儲在位viewBitMap

+0

我想改變圖像位圖圖像不是我。 – Ramakrishna

+0

什麼我不能明白嗎?我是ImageView的 –

+0

LoaderImageView返回一個ImageView的(圖片)。我要轉換一個是ImageView的位圖圖像,然後將其設置爲GridView的圖像(I)。 – Ramakrishna

0

看:

ImageView.getDrawingCache(); 

但你要記住,返回Bitmap不會是一樣的,你從資源或文件得到的,因爲Bitmap將取決於顯示器的物理特性(分辨率,縮放,顏色深度等)。

0

這將工作:

ImageView img; 
img.setDrawingCacheEnabled(true); 
Bitmap scaledBitmap = img.getDrawingCache(); 

//商店tmp文件

 String extr = Environment.getExternalStorageDirectory().toString(); 
     File mFolder = new File(extr + "/tmpfolder"); 
     if (!mFolder.exists()) { 
      mFolder.mkdir(); 
     } 

     String s = "tmp.png"; 

     File f = new File(mFolder.getAbsolutePath(), s); 

     strMyImagePath = f.getAbsolutePath(); 
     FileOutputStream fos = null; 
     try { 
      fos = new FileOutputStream(f); 
      scaledBitmap.compress(Bitmap.CompressFormat.PNG, 70, fos); 
      fos.flush(); 
      fos.close(); 
     } catch (FileNotFoundException e) { 

      e.printStackTrace(); 
     } catch (Exception e) { 

      e.printStackTrace(); 
     } 

     scaledBitmap.recycle(); 
    } catch (Throwable e) { 
    }