新聞中心
Android操作系統(tǒng)中對于圖片的操作我們在以前的文章中也有所介紹。不過對于圖片的大小調(diào)整往往都局限于固定的調(diào)整。如何才能滿足動態(tài)大小調(diào)整呢?我們在這里就為大家詳細(xì)介紹有關(guān)Android圖片大小調(diào)整的動態(tài)實(shí)現(xiàn)方法。

涿鹿ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!
昨天,動態(tài)獲取圖片資源獲取的很爽啊,后來,換了一張png,128*128的,Run as android application,天哪,居然覆蓋了我大半個(gè)屏幕,都不留一點(diǎn)情面給我展示了。。。。看來,必須要找個(gè)方法讓圖片自適應(yīng)大小,于是修改了一下獲取圖片的代碼,讓圖片能自適應(yīng)。
一下就是Android圖片大小調(diào)整的相關(guān)代碼示例:
- 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是欲縮放后的大小,這里加個(gè)參數(shù)how是防止有不需要縮放的情況~
Android圖片大小調(diào)整的操作方法就為大家介紹到這里。
【編輯推薦】
- Android界面互調(diào)具體應(yīng)用方式解析
- Android智能指針使用方法介紹
- Android查詢聯(lián)系人信息正確操作方法
- Android命令行啟動程序正確使用技巧解析
- 全方位解讀Android多媒體框架源碼
名稱欄目:Android圖片大小調(diào)整動態(tài)實(shí)現(xiàn)方法
路徑分享:http://www.fisionsoft.com.cn/article/ccegshe.html


咨詢
建站咨詢
