Common Bitmap operations in Android (1. theory)

Source: Internet
Author: User

// Use BitmapFactory to generate Bitmap
// Note that this method only generates Bitmap, so the returned value is a Bitmap.
// Operations on Bitmap objects are not involved, such as rotating and compressing Bitmap objects.
// The following are four common methods:
// 1 generate Bitmap Based on the file path
// This method is also one of the methods for obtaining thumbnails.
// Another method for obtaining thumbnails is to call the class method directly.
// Focus on the input parameter opts
// ThumbnailUtils. extractThumbnail ();
// It can be understood as follows: since a scaling chart is generated
// New Bitmap, so of course the BitmapFactory. decodeFile () method should be called.
Bitmap bitmap1 = BitmapFactory. decodeFile (pathName, opts );
// 2 generate Bitmap from local resources
Bitmap bitmap2 = BitmapFactory. decodeResource (res, id );
// 3 generate Bitmap from the input stream
Bitmap bitmap3 = BitmapFactory. decodeStream (inputStream );
// 4 generate Bitmap from byte array
Bitmap bitmap4 = BitmapFactory. decodeByteArray (data, offset, length );

// After generating a Bitmap, the Bitmap operations are summarized as follows:
// 1. compress the Bitmap width and height to rotate and tilt Bitmap.
// And other operations call the Bitmap. createBitmap () method of the class method. The matrix parameter is very important.
Bitmap bitmap5 = Bitmap. createBitmap (rawBitmap, x, y, width, height, matrix, filter );
// 2 save Bitmap to the file. The object method of Bitmap is called.
Bitmap5.compress (format, quality, OS );

Related Article

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.