Overlapping Android Images

Source: Internet
Author: User

Convert an image into a bitmap object and draw it through a canvas layer by layer. Of course, a bitmap object can be used for image rotation, image scaling, and other functions.
Private bitmap drawpicture (Bitmap mbitmap)
{
Bitmap bitmap = mbitmap;
// Bitmapfactory. decoderesource (getresources (), R. drawable. mymoive_01 );
Bitmap mbitmap = bitmap. createbitmap (bitmap. getwidth () + 4, bitmap. getheight () + 4, bitmap. config. argb_8888 );
Canvas mcanvas = new canvas (mbitmap );
Paint mpaint = new paint ();

Mpaint. setcolor (color. White );
Mcanvas. drawrect (0, 0, bitmap. getwidth () + 4, bitmap. getheight () + 4, mpaint );
Mcanvas. drawbitmap (bitmap, 2, 2, new paint ());
Mcanvas. Save (canvas. all_save_flag );
Mcanvas. Restore ();

Matrix matrix = new matrix ();
Matrix. setrotate (8 );
Bitmap newbitmap = bitmap. createbitmap (mbitmap, 0, 0, mbitmap. getwidth (), mbitmap. getheight (), matrix, true );
Matrix. setrotate (5 );
Bitmap xbitmap = bitmap. createbitmap (mbitmap, 0, 0, mbitmap. getwidth (), mbitmap. getheight (), matrix, true );

Canvas canvas = new canvas (newbitmap );
Canvas. drawbitmap (xbitmap, 0, 0, new paint ());
Canvas. drawbitmap (mbitmap, 0, 4, new paint ());
Canvas. drawbitmap (mbitmap, 0, 10, new paint ());
Canvas. Save (canvas. all_save_flag );
Canvas. Restore ();
String filename = "/sdcard/12.png ";
File file = new file (filename );

Fileoutputstream out;
Try {
File. createnewfile ();
Out = new fileoutputstream (File );
Newbitmap. Compress (bitmap. compressformat. PNG, 100, out );
Log. E ("system. Out", "Save OK ");
} Catch (filenotfoundexception e ){
// Todo auto-generated Catch Block
Log. E ("system. Out", E. tostring ());
E. printstacktrace ();
} Catch (ioexception e ){
// Todo auto-generated Catch Block
Log. E ("system. Out", E. tostring ());
E. printstacktrace ();
}


Return newbitmap;
}

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.