麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

加載asset文件夾下邊的圖片

2019-11-09 15:40:29
字體:
來源:轉載
供稿:網友

將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表示顯示區域(位圖會拉伸填充該區域)

在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);  }


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 黄色高清免费 | 性片久久| 午夜久久久精品一区二区三区 | 精精国产xxxx视频在线野外 | 九九视频久久 | 欧美在线中文字幕 | 黑人一区二区三区四区五区 | 伊人99在线 | 成人h精品动漫一区二区三区 | 欧美一级高潮 | 插插操 | 99精品视频免费看 | 久久精品在这里 | 91国内精品久久久久免费影院 | 老司机免费福利午夜入口ae58 | 亚洲午夜视频 | 2021狠狠操 | av手机在线免费播放 | 法国性xxx精品hd专区 | 日本黄色一级视频 | 国产成人免费精品 | 31freehdxxxx欧美| 毛片区 | www.精品一区 | 国产精品视频一区二区三区四 | 国产免费一区 | 久久亚洲美女视频 | 久草手机在线 | 亚洲精品午夜国产va久久成人 | 双性精h调教灌尿打屁股的文案 | chinesexxxx极品少妇 | 91成人久久 | 天海翼无删减av三级在线观看 | 亚洲成人精品国产 | 黄色二区三区 | 国产资源在线播放 | 国产精品久久久久久久久久10秀 | 国产一区二区三区在线免费观看 | 草草视频在线播放 | 欧美成人黄色小视频 | 国产毛毛片一区二区三区四区 |