Android image gradient Processing

Source: Internet
Author: User

Http://stackoverflow.com/questions/8417608/awful-background-image-quality-in-android/8417703#8417703

First of all, make sure that your original image looks good so you're not just getting the problem from there.
Then, in your oncreate () method, do:

Code1:

 
Getwindow().Setformat(Pixelformat.Rgba_8888);Getwindow().Addflags(Windowmanager.Layoutparams.Flag_dither);

And to load your image explicitly as a 32-bit image (RGBA-8888 configuration) Add the following where you load your views:

Code2:

 Bitmapfactory  .  Options  Options  =     New     Bitmapfactory  .  Options  ();  Options  .  Inpreferredconfig  =     Bitmap .  Config  .  Argb_8888  ;    Bitmap  Gradient  =     Bitmapfactory  .  Decoderesource  (  Getresources  (),  R  .  Drawable  .  Gradient  , Options  );  Findviewbyid  (  R  .  ID  .  Main  ).  Setbackgrounddrawable  (  New     Bitmapdrawable  (  Gradient  )); 

Comparison between different approaches :( these are all screenshots from the resulting application)

my source images (64 colors to the left, 24 bit to the right):
image1 and image2:
1: raw 64-color image (image1) set as background from layout XML:
2: the same image (image1 ), using code1 :
3: The same image (image1) using both code1 and code2 :
4: image2, loaded with code1 and code2 (in this case the dithering is not really important as both the source and destination use 8 bits per color):

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.