1. image loading method to help users load images
Java code
- /***
- * Load local Images
- *
- * @ Param Context
- *: Main running function instance
- * @ Param bitadress
- *: 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
Java code
- /***
- * 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
Java code
- /***
- * 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
Java code
- /***
- * 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 ();
- }
5. The easiest way to separate images
Java code
- Public final bitmap cuteimage (Bitmap _ imgbit, int _ startx, int width,
- Int _ starty, int height ){
- Bitmap tempmap = NULL;
- Tempmap = bitmap. createbitmap (_ imgbit, _ startx, _ starty, width, height );
- Return tempmap;
- }
6. String branch display
Java code
- Public String [] stringformat (string text, int maxwidth, int fontsize ){
- String [] result = NULL;
- Vector <string> tempr = new vector <string> ();
- Int lines = 0;
- Int Len = text. Length ();
- Int index0 = 0;
- Int index1 = 0;
- Boolean wrap;
- While (true ){
- Int widthes = 0;
- Wrap = false;
- For (index0 = index1; index1 <Len; index1 ++ ){
- If (text. charat (index1) = '\ n '){
- Index1 ++;
- Wrap = true;
- Break;
- }
- Widthes = fontsize + widthes;
- If (widthes> maxwidth ){
- Break;
- }
- }
- Lines ++;
- If (WRAP ){
- Tempr. addelement (text. substring (index0, index1-1 ));
- } Else {
- Tempr. addelement (text. substring (index0, index1 ));
- }
- If (index1> = Len ){
- Break;
- }
- }
- Result = new string [Lines];
- Tempr. copyinto (result );
- Return result;
- }