国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

加載asset文件夾下邊的圖片

2019-11-09 16:50:44
字體:
供稿:網(wǎng)友

將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");              // 讀入圖片并將其強(qiáng)轉(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表示原圖尺寸,第二個(gè)rect表示顯示區(qū)域(位圖會拉伸填充該區(qū)域)

在onDraw()中繪制位圖需要用到的方法(源碼):

    /**     * Draw the specified bitmap, scaling/translating automatically to fill     * the destination rectangle. If the source rectangle is not null, it     * specifies the subset of the bitmap to draw.     *     * <p>Note: if the paint contains a maskfilter that generates a mask which     * extends beyond the bitmap's original width/height (e.g. BlurMaskFilter),     * then the bitmap will be drawn as if it were in a Shader with CLAMP mode.     * Thus the color outside of the original width/height will be the edge     * color replicated.     *     * <p>This function <em>ignores the density associated with the bitmap</em>.     * This is because the source and destination rectangle coordinate     * spaces are in their respective densities, so must already have the     * apPRopriate scaling factor applied.     *     * @param bitmap The bitmap to be drawn     * @param src    May be null. The subset of the bitmap to be drawn     * @param dst    The rectangle that the bitmap will be scaled/translated     *               to fit into     * @param paint  May be null. The paint used to draw the bitmap     */    public void drawBitmap(@NonNull Bitmap bitmap, @Nullable Rect src, @NonNull RectF dst,            @Nullable Paint paint) {      if (dst == null) {          throw new NullPointerException();      }      throwIfCannotDraw(bitmap);      final long nativePaint = paint == null ? 0 : paint.getNativeInstance();      float left, top, right, bottom;      if (src == null) {          left = top = 0;          right = bitmap.getWidth();          bottom = bitmap.getHeight();      } else {          left = src.left;          right = src.right;          top = src.top;          bottom = src.bottom;      }      native_drawBitmap(mNativeCanvasWrapper, bitmap, left, top, right, bottom,              dst.left, dst.top, dst.right, dst.bottom, nativePaint, mScreenDensity,              bitmap.mDensity);  }


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 屏东县| 揭西县| 那坡县| 丘北县| 潼关县| 通辽市| 罗江县| 临夏市| 霍林郭勒市| 宜章县| 彭山县| 新竹市| 澎湖县| 太谷县| 永清县| 庆元县| 博兴县| 南部县| 界首市| 东丰县| 昭觉县| 合川市| 辛集市| 肃宁县| 富顺县| 张北县| 长宁县| 祁东县| 清水河县| 民勤县| 元氏县| 清涧县| 浏阳市| 达州市| 德保县| 凌云县| 富顺县| 荣昌县| 绥棱县| 花莲县| 阿拉善左旗|