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 leads to a long waste of time to find out why, so hurry to 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, there is wood, 700*450, but read out is 525*337. If you have encountered this kind of situation, please look down

This mistake, we can only blame the drawable-ldpi, the reason is that you do not in the corresponding resource folder to put the picture is (mdpi ldpi), you must have only a folder

For example, compared to the film a 700*450 only in the MDPI, when Android will first determine the screen dpi if it is 120, it will go to ldpi, if it is 160 to mdpi, if it is 240 go hdpi

If it goes to ldpi and finds out you don't have a picture, it goes to mdpi, but it will scale the image to 525*337 approximate resolution. The algorithm is 700*0.75 450*0.75 = 525 * 337

See here if you're not quite sure about the numbers, get to know the dpi density, the DPI and pixel relationships, and so on.

The solution, at present, I have copied the picture into all the Pictures folder. So it will find the corresponding. It's normal to get the picture's width high.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.