欢迎来到代码驿站!

Android代码

当前位置:首页 > 移动开发 > Android代码

Android 加载asset文件夹下边的图片

时间:2021-04-27 09:07:45|栏目:Android代码|点击:

将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部分手机拍照后获取的图片被旋转问题的解决方法

栏    目:Android代码

下一篇:Android拍照和获取相册图片

本文标题:Android 加载asset文件夹下边的图片

本文地址:http://www.codeinn.net/misctech/109609.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有