Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to adjust picture size dynamically in Android

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article "how to dynamically resize pictures in Android", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to dynamically resize pictures in Android" article.

Sample code for resizing Android images:

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

Among them, scaleWidth and scaleHeight are the size after scaling. Here, a parameter how is added to prevent cases where scaling is not necessary.

The above is about the content of this article on "how to dynamically resize pictures in Android". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report