Use canvas in Android to draw images at the specified position and width and height

Source: Internet
Author: User
/*---------------------------------
* Draw an image
* @ Param X coordinates on the screen
* @ Param y coordinate on the screen
* @ Param w the width of the image to be drawn
* @ Param h the height of the image to be drawn
* @ Param bx x coordinate on the Image
* @ Param by Y coordinate on the Image
*
* @ Return null
------------------------------------*/

Public static void drawimage (canvas, bitmap BLT, int X, int y,
Int W, int H, int BX, int ){
Rect src = new rect (); // picture> original rectangle
Rect DST = new rect (); // screen> Target rectangle

SRC. Left = Bx;
SRC. Top =;
SRC. Right = bx + W;
SRC. Bottom = by + h;

DST. Left = X;
DST. Top = y;
DST. Right = x + W;
DST. Bottom = Y + h;
// Draw the specified bitmap. The bitmap will be automatically scaled/automatically converted to fill the target rectangle.
// The meaning of this method is like re-drawing a bitmap as needed. The bitmap after painting is what we need.
Canvas. drawbitmap (BLT, null, DST, null );
Src = NULL;
DST = NULL;
}

/**
* Draw a bitmap
*
* @ Param canvas
* @ Param bitmap image
* @ Param X coordinates on the screen
* @ Param y coordinate on the screen
*/

Public static void drawimage (canvas, Bitmap bitmap, int X, int y ){
// Draw an image and display the bitmap object on coordinates X and Y.
Canvas. drawbitmap (bitmap, X, Y, null );
}

 

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.