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

What is the reason why surfacechanged appears?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you what is the reason for the emergence of surfacechanged, I hope you will gain something after reading this article, let's discuss it together!

The reason for the emergence of surfacechanged

The screen resolution is fixed, but the preview resolution can be modified.

For example, (the following units are all px, in order to understand that our fixed phone is vertical screen, horizontal as wide, vertical as high) the current preview resolution is 1280960 (4:3) the phone screen resolution is 19201080 (16:9) set surfaceview fixed case is the width and height is set to match_parent, then its height is the height of the screen width of 1920 to 1080. As a result, we forcibly put the picture with a width of 960 pixels on the canvas with a width of 1080, resulting in a certain stretch horizontally, and in the same way, it was pulled vertically from 1280 to 1920. Obviously, the width magnified 1080amp 960x, the height magnified 1920amp 1280x, these two values are definitely not equal, leading to preview deformation.

Surfacechanged solution

The first is to choose the appropriate resolution.

As mentioned above, since the screen resolution is dead, let's first get the screen resolution and then set the preview resolution to be the same as the screen resolution, or the scale is the same.

1. Get screen resolution

two。 Set the resolution of the preview (before that, you need to get the resolution supported by this phone. It will be a problem if you set it incorrectly)

This is the preview resolution supported by my test machine.

For example, if the resolution of the mobile phone is 19201080, then the first call to parameters.setPreviewSize (); can be solved perfectly. Now there are many high-resolution mobile phones, or long-screen mobile phones, the author's test machine screen resolution is 22801080, but there is no appropriate resolution, this method can not be solved, take a look at the second.

After reading this article, I believe you have a certain understanding of "what is the reason for the emergence of surfacechanged". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

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