Android image processing

Source: Internet
Author: User

1 Reading pictures

2 conversion between drawable and bitmap

2.1 drawable >> Bitmap

The drawable we often refer to is just an abstract class, in which we are actually dealing with derived classes, such as bitmapdrawable (PNG images), gradientdrawable (XML images), and so on. If the given drawable is an instance of bimapdrawable, we can call its Getbitmap method directly, otherwise create a bitmap and draw drawable onto the bitmap.

 public static final Bitmap Drawabletobitmap (drawable drawable) {if (Drawa        ble instanceof bitmapdrawable) {return ((bitmapdrawable) drawable). Getbitmap (); } else {///according to the creation of a Bitmap with drawable size Bitmap Bitmap = Bitmap.createbitmap (drawabl E.getintrinsicwidth (), Drawable.getintrinsicheight (),//determines the pixel format of the drawable ARGB or RGB, i.e. Is there transparency if there is no transparency, choose rgb_565, save space for storage transparency drawable.getopacity ()! = Pixelformat.opaque?            Bitmap.Config.ARGB_8888:Bitmap.Config.RGB_565);            Create a canvas with bitmap, draw on canvas is actually draw on the bitmap canvas canvas = new canvas (bitmap); Draw () is actually based on the drawable bounds to determine the drawing position, so set bounds drawable.setbounds (0, 0, drawable.getintrinsicwidth (), drawab            Le.getintrinsicheight ());            Draw the drawable on the canvas drawable.draw (canvas);        return bitmap; }    }

The above code relates to Bitmap.config, which is a detailed introduction to this article:http://www.cnblogs.com/and_he/archive/2012/12/22/ARGB.html

2.2 Bitmap >> drawable

Bitmap can be converted to drawable via bitmapdrawable:

public static final drawable bitmaptodrawable (Bitmap Bitmap) {    return new bitmapdrawable (BITMAP);
}

Android image processing

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.