How Android obtains images of real pixels through bitmapfactory, and why it doesn't get real pixels

Source: Internet
Author: User

Original from: Original address

Because this error causes a lot of wasted time to find out why, so hurry up and record it.

The process is this, when using Android to read pictures, is the use of Bitmapfactory.decoderesource (This.getresources (), r.drawable.base) when

The size of the returned picture is not the same as the real picture size, for example, the picture is 700*450, but read out is 525*337. If you have encountered this kind of situation, please look down

This mistake, just can blame us for not fine, because you did not in the corresponding resource directory in the picture is (drawable-ldpi mdpi ldpi), you must only put a directory

For example, for example, picture a 700*450 just put in mdpi, when Android will first infer that the screen dpi hypothesis is 120 it went to ldpi, assuming 160 went to mdpi, assuming 240 went hdpi

Assuming it went to ldpi and found out you didn't have a picture, it went to MDPI, but it would scale the image to 525*337 approximate resolution.

The algorithm is 700*0.75 450*0.75 = 525 * 337

See here assuming you're not quite sure about these numbers, go to the dpi density, the DPI and pixel relationships, and so on.

By the way, I am now copying the pictures into the entire catalogue. So it will find the corresponding.

It's normal to get the picture's width high.

How Android obtains images of real pixels through bitmapfactory, and why it doesn't get real pixels

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.