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