In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 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 optimize WeChat Mini Programs's picture 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 optimize WeChat Mini Programs's picture in Android" article.
Wechat stipulates that the pictures displayed by sharing Mini Program should be within 128KB, and the default display ratio of pictures is 5:4, so the default pictures of side dishes are many vertical ones, only some of them are displayed.
Obscure part of the picture
Regulation
The side dish has tried [proportional compression] [non-proportional compression] and [non-compression] of the image, and the effect is still inappropriate. By default, the position occupied by the image fills the shared layout in the horizontal direction. So the dish decided to re-draw a picture with Canvas and center the picture to be displayed. The arrangement is as follows:
Public static Bitmap drawWXMiniBitmap (Bitmap bitmap, int width, int height) {Bitmap mBitmap = Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888); / / generate a Canvas with this Bitmap, and then canvas will draw the content to the above bitmap Canvas mCanvas = new Canvas (mBitmap); / / paint brush Paint mPicturePaint = new Paint (); / / draw background picture mCanvas.drawBitmap (mBitmap, 0.0f, 0.0f, mPicturePaint) / / draw the width and height of the picture int width_head = bitmap.getWidth (); int height_head = bitmap.getHeight (); / / draw the picture-- make sure it is centered horizontally mCanvas.drawBitmap (bitmap, (width-width_head) / 2, (height-height_head) / 2, mPicturePaint); / / Save the drawing as a local picture mCanvas.save (); mCanvas.restore (); return mBitmap;}
Side dish test found that the size and aspect ratio of many pictures are not fixed, in order to adapt to the overall display effect, when the aspect ratio is less than 1, according to the picture height to calculate the overall drawing Bitmap width, Bitmap can be based on demand to show the corresponding local resource map or network map, width and height can be directly set the size of 5:4, snack test width = 300; height = 240overall effect is more appropriate. You can customize the picture style according to your personal needs.
Bitmap bitmap = BitmapUtil.drawWXMiniBitmap (bitmap, bitmap.getHeight () * 5 / 4, bitmap.getHeight ()); if (BitmapUtil.isOverSize (bitmap)) {bitmap = Utils.resizeBitmap (bitmap, 300,240);}
Tips: after drawing, the picture will be larger than the original image, so you need to draw the picture first, and then determine whether the picture exceeds the 128KB. If more than 128KB needs to be compressed, the public method will be omitted for the time being!
The above is about the content of this article on "how to optimize WeChat Mini Programs's picture 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.