欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android 加載asset文件夾下邊的圖片

 更新時間:2017年02月08日 17:11:17   作者:AngleElina  
這篇文章主要介紹了Android 加載asset文件夾下邊的圖片,非常不錯,具有參考借鑒價值,需要的朋友可以參考下

將asset中的圖片文件加載到ImageView中

// load image  
    try {  
      // get input stream  
      InputStream ims = getAssets().open("avatar.jpg");  
      // load image as Drawable  
      Drawable d = Drawable.createFromStream(ims, null);  
      // set image to ImageView  
      mImage.setImageDrawable(d);  
    }  
    catch(IOException ex) {  
      return;  
    }  

將asset中的圖片文件繪制到自定義View中。

Bitmap bitmap; 
    try {  
      InputStream ims = this.getContext().getAssets().open("fl.jpg");  
      // 讀入圖片并將其強轉(zhuǎn)為 BitmapDrawable類型 
      BitmapDrawable bd = (BitmapDrawable) Drawable.createFromStream(ims, null); 
      bitmap = bd.getBitmap(); 
      ims.close(); 
    }  
    catch(IOException ex) {  
      return;  
    }  
    //canvas.drawBitmap(bitmap, -200, -200, new Paint()); 
    canvas.drawBitmap(bitmap, null, new Rect(-30,-40,30,40), new Paint());//null表示原圖尺寸,第二個rect表示顯示區(qū)域(位圖會拉伸填充該區(qū)域) 

以上所述是小編給大家介紹的Android 加載asset文件夾下邊的圖片,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評論