Android中如何动态调整图片大小

发布时间:2022-04-16 16:15:35 作者:iii
来源:亿速云 阅读:302

这篇“Android中如何动态调整图片大小”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“Android中如何动态调整图片大小”文章吧。

Android图片大小调整的相关代码示例:

view plaincopy to clipboardprint?  private Bitmap getImageFromAssetFile(String fileName,int how){   Bitmap image = null ;   try {   AssetManager am = game.getAssets();   InputStream is = am.open(fileName);   image = BitmapFactory.decodeStream(is);   is.close();   }catch (Exception e){   }   return zoomImage(image,how);   }   public Bitmap zoomImage(Bitmap bgimage,int how) {   int bmpwidth = bgimage.getWidth();   int bmpheight = bgimage.getHeight();   float scaleWidth=0;   float scaleHeight=0;   Matrix matrix = new Matrix();   if(how==0){   scaleWidth = ((float) width) / bmpwidth;   scaleHeight = ((float) height) / bmpheight;   }else{   scaleWidth=Math.min(width,height)/bmpwidth;   scaleHeight=Math.min(width, height)/bmpheight;   }   private Bitmap getImageFromAssetFile(String fileName,int how){   Bitmap image = null ;   try {   AssetManager am = game.getAssets();   InputStream is = am.open(fileName);   image = BitmapFactory.decodeStream(is);   is.close();   }catch (Exception e){   }   return zoomImage(image,how);   }   public Bitmap zoomImage(Bitmap bgimage,int how) {  int bmpwidth = bgimage.getWidth();  int bmpheight = bgimage.getHeight();  float scaleWidth=0;  float scaleHeight=0;  Matrix matrix = new Matrix();  if(how==0){  scaleWidth = ((float) width) / bmpwidth;  scaleHeight = ((float) height) / bmpheight;  }else{  scaleWidth=Math.min(width,height)/bmpwidth;  scaleHeight=Math.min(width, height)/bmpheight;  }

其中,scaleWidth和scaleHeight是欲缩放后的大小,这里加个参数how是防止有不需要缩放的情况。

以上就是关于“Android中如何动态调整图片大小”这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注亿速云行业资讯频道。

推荐阅读:
  1. 将android中如何调整Toast位置?
  2. android   动态改变图片大小

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android

上一篇:Android中如何设置屏幕大小

下一篇:Android中如何实现垃圾回收

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》