將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"); // 讀入圖片并將其強轉為 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表示顯示區域(位圖會拉伸填充該區域) 以上所述是小編給大家介紹的Android 加載asset文件夾下邊的圖片,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答