Android ImageView. getDrawingCache is NULL

Source: Internet
Author: User

First, the source image is displayed in the ImageView (regardless of the image size, if the image is large, the proportion of the ImageVIew is reduced), because the image is processed by the user, of course, the smaller the image, the faster the processing, the better, so the project decided to use a copy of the image display for processing rather than the source image (because the source image may be large ).

Problem:

In order to steal some laziness, I am from ImageView. the copy obtained by the getDrawingCache method, because this copy is the real display size copy (imageView. getDrawable, this method gets the image of the source image size), my code is as follows:
View source
 

1 imageView. setDrawingCacheEnabled (Boolean. TRUE );
2 Bitmap tempBitmap = Bitmap. createBitmap (imageView. getDrawingCache ());
3 imageView. setDrawingCacheEnabled (Boolean. FALSE); // clear drawing cache
This code is okay when I run it on the simulator. tempBitmap has a value and is not null;

When I tested it on a real machine, the problem occurred. The tempBitmap is null; The imageView. getDrawingCache () method didn't get the cache at all.

I checked some other information on the Internet and tried to solve the problem. I hope someone else can give me some advice.

Development Environment: android 2.3.3 and android 2.3.5

Is it because of this version?

「 Here, I found some information abroad, which may be useful. I did not solve this problem, but many others did. 」
Http://www.bkjia.com/kf/201203/123437.html

From tonyley3

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.