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