Image processing methods in Android

Source: Internet
Author: User
Tags drawtext

1. image loading method to help users load images
/***
* Load local Images
* @ Param context: Main running function instance
* @ Param bitadress: Specifies the image address, which generally points to the drawable directory under R.
* @ Return
*/
Public final bitmap creatimage (context, int bitadress ){
Bitmap bitmaptemp = NULL;
Bitmaptemp = bitmapfactory. decoderesource (context. getresources (),
Bitadress );
Return bitmaptemp;
}
2. The image mean segmentation method divides a larger image into N rows and n columns on average for ease of use
/***
* Image Segmentation
*
* @ Param g
*: Canvas
* @ Param paint
*: Paint brush
* @ Param imgbit
*: Image
* @ Param x
*: X-axis start Coordinate
* @ Param y
*: Y-axis start Coordinate
* @ Param W
*: Width of a single image
* @ Param H
*: Height of a single image
* @ Param line
*: Column number
* @ Param row
*: Row number
*/
Public final void cuteimage (canvas g, paint, bitmap imgbit, int X,
Int y, int W, int H, int line, int row ){
G. cliprect (X, Y, x + W, H + y );
G. drawbitmap (imgbit, X-line * w, Y-row * H, paint );
G. Restore ();
}
3. resize the current image
/***
* Image Scaling Method
*
* @ Param bgimage
*: Source image resources
* @ Param newwidth
*: Width after scaling
* @ Param newheight
*: Zoom height
* @ Return
*/
Public bitmap zoomimage (Bitmap bgimage, int newwidth, int newheight ){
// Obtain the width and height of the image.
Int width = bgimage. getwidth ();
Int Height = bgimage. getheight ();
// Create a matrix object for image operations
Matrix matrix = new matrix ();
// Calculate the zooming rate. The new size excludes the original size.
Float scalewidth = (float) newwidth)/width;
Float scaleheight = (float) newheight)/height;
// Scaling the image
Matrix. postscale (scalewidth, scaleheight );
Bitmap bitmap = bitmap. createbitmap (bgimage, 0, 0, width, height,
Matrix, true );
Return bitmap;
}
4. Draw text with borders, which is generally used to beautify the text in the game
/***
* Draw text with borders
*
* @ Param strmsg
*: Draw content
* @ Param g
*: Canvas
* @ Param paint
*: Paint brush
* @ Param setx
*: Start coordinate of the X axis
* @ Param sety
*: Start coordinate of the Y axis
* @ Param FG
*: Foreground color
* @ Param BG
*: Background Color
*/
Public void drawtext (string strmsg, canvas g, paint, int setx,
Int sety, int FG, int BG ){
Paint. setcolor (BG );
G. drawtext (strmsg, setx + 1, sety, paint );
G. drawtext (strmsg, setx, sety-1, paint );
G. drawtext (strmsg, setx, sety + 1, paint );
G. drawtext (strmsg, setx-1, sety, paint );
Paint. setcolor (FG );
G. drawtext (strmsg, setx, sety, paint );
G. Restore ();
}

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/xyz_lmn/archive/2009/08/29/4497092.aspx

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.