SoFunction
Updated on 2025-04-09

Android implements the method of rotating, enlarging, and reducing pictures

This article describes the method of Android to rotate, zoom in and reduce pictures. Share it for your reference, as follows:

A preview image function is required in the project

Initially, I imagine that I can customize a view. In onDraw, I use the generation of a new Bitmap to zoom in and out.

However, since the mobile phone memory is limited, it will be cored after magnification several times.

Later, we directly select imageview to complete this task. Unfortunately, although the bitmap will not be generated repeatedly to cause core loss, the size limit of the imageview is that the image cannot be enlarged or enlarged, and can only be in this area.

Finally, choose to use Drawable.

private Drawable image;
private int picWidth;
private int picHeight;
@Override
protected void onDraw(Canvas canvas) {
  (canvas);
  //Pics zoom is controlled using picwidth and picheight  int l = (getWidth() - picWidth) / 2;
  int r = (getWidth() + picWidth) / 2;
  int t = (getHeight() - picHeight) / 2;
  int b = (getHeight() + picHeight) / 2;
  (l, t, r, b);
  (rotateDegre, getWidth() / 2, getHeight() / 2); //Rotate the picture  (canvas);
}

For more information about Android related content, please check out the topic of this site:Summary of Android graphics and image processing skills》、《Android development introduction and advanced tutorial》、《Android debugging skills and solutions to common problems》、《Android multimedia operation skills summary (audio, video, recording, etc.)》、《Summary of the usage of basic Android components》、《Android View View Tips Summary》、《Android layout layout tips summary"and"Android control usage summary

I hope this article will be helpful to everyone's Android programming design.