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 optimize WeChat Mini Programs's picture in Android

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

Share

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

This article mainly explains "how to optimize the pictures of Weixin Mini Programs in Android." The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian to study and learn "how to optimize the pictures of Weixin Mini Programs in Android" together!

preface

WeChat stipulates that the pictures displayed by sharing Mini programs should be within 128KB, and the default display ratio of pictures is 5:4. In this way, many default pictures of dishes are vertical pictures and only part of them will be displayed.

Occluded partial picture

provisions

Xiaocai tried [Equal compression],[Non-equal compression] and [Uncompressed] of the picture, but the effect was still inappropriate. The position occupied by the picture was filled with the shared layout in the horizontal direction by default. So Xiaocai decided to redraw a picture with Canvas and display the picture to be displayed in the center. The arrangement method is as follows:

public static Bitmap drawWXMiniBitmap (Bitmap bitmap, int width, int height) { Bitmap mBitmap = Bitmap.createBitmap (width, height, Bitmap.Config.ARGB_8888); //Use this Bitmap to generate a Canvas, and then canvas will draw the content to the bitmap above Canvas mCanvas = new Canvas(mBitmap); //Paint Paint mPicturePaint = new Paint();//draw background image mCanvas.drawBitmap (mBitmap, 0.0f, 0.0f, mPicturePaint); //Draw width and height of 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;}

During the dish test, it is 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, calculate the overall drawing Bitmap width according to the height of the picture. Bitmap can display the corresponding local resource map or network map according to the demand. The width and height can be directly set to 5:4. The overall effect of the dish test width = 300; height = 240 is more appropriate. You can customize the image style according to your personal needs.

Bitmap bitmap = BitmapUtil.drawWXMiniBitmap(bitmap, bitmap.getHeight() * 5 / 4, bitmap.getHeight());if (BitmapUtil.isOverSize(bitmap, 128)) { bitmap = Utils.resizeBitmap(bitmap, 300, 240);}

Tips: After drawing, the image will be larger than the original image, so you need to draw the image first, and then determine whether the image exceeds 128KB. If more than 128KB needs to be compressed, the public method will be omitted for the time being!

Thank you for reading. The above is the content of "How to optimize the pictures of Weixin Mini Programs (Mini) in Android." After studying this article, I believe you have a deeper understanding of how to optimize the pictures of Weixin Mini Programs in Android. The specific use situation needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

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