SoFunction
Updated on 2025-04-10

Android image processing example analysis

This article describes the method of Android image processing. Share it for your reference, as follows:

package ;
import ;
import ;
import ;
import ;
import ;
import ;
public class Utils {
     /***
      * Load local image
      * @param context: Main running function instance
      * @param bitAdress: The image address, generally pointing to the drawable directory under R
      * @return
      */
    public final Bitmap CreatImage(Context context, int bitAdress) {
        Bitmap bitmaptemp = null;
        bitmaptemp = ((),bitAdress);
        return bitmaptemp;
    }
//2. The average image segmentation method, splitting the large image into N rows and N columns evenly, making it convenient for users to use    /***
      * Image segmentation
      * @param g
      *: Canvas
      * @param paint
      *:brush
      * @param imgBit
      *:picture
      x
      *: X-axis starting point coordinates
      * @param y
      *: Y-axis starting point coordinate
      * @param w
      *: Width of a single picture
      * @param h
      *: The height of a single picture
      * @param line
      *: Which column
      * @param row
      *: Which line
      */
    public final void cuteImage(Canvas g, Paint paint, Bitmap imgBit, int x,
            int y, int w, int h, int line, int row) {
        (x, y, x + w, h + y);
        (imgBit, x - line * w, y - row * h, paint);
        ();
    }
//3. Image scaling, scaling the current image    /***
      * Image scaling method
      * * @param bgimage
      *: Source image resources
      * @param newWidth
      *: Width after zooming
      * @param newHeight
      *: The height after zooming
      * @return
      */
    public Bitmap zoomImage(Bitmap bgimage, int newWidth, int newHeight) {
        // Get the width and height of this picture        int width = ();
        int height = ();
        // Create matrix object for operation pictures        Matrix matrix = new Matrix();
        // Calculate the scaling rate, and the new size is separated from the original size        float scaleWidth = ((float) newWidth) / width;
        float scaleHeight = ((float) newHeight) / height;
        // Zoom the image action        (scaleWidth, scaleHeight);
        Bitmap bitmap = (bgimage, 0, 0, width, height,
                matrix, true);
        return bitmap;
    }
//4. Drawing text with borders generally serves as a beautifying text in the game    /**
      * Draw text with borders
      * @param strMsg
      *: Draw content
      * @param g
      *:canvas
      * @param paint
      *:brush
      * @param setx
      *: X-axis starting coordinate
      * @param sety
      *: The starting coordinate of the Y axis
      * @param fg
      *: Foreground color
      * @param bg
      *: Background color
      */
    public void drawText(String strMsg, Canvas g, Paint paint, int setx,
            int sety, int fg, int bg) {
        (bg);
        (strMsg, setx + 1, sety, paint);
        (strMsg, setx, sety - 1, paint);
        (strMsg, setx, sety + 1, paint);
        (strMsg, setx - 1, sety, paint);
        (fg);
        (strMsg, setx, sety, paint);
        ();
    }
}

For more information about Android related content, please check out the topic of this site:Summary of Android graphics and image processing skills》、《Android development introduction and advanced tutorial》、《Android debugging skills and solutions to common problems》、《Android multimedia operation skills summary (audio, video, recording, etc.)》、《Summary of the usage of basic Android components》、《Android View View Tips Summary》、《Android layout layout tips summary"and"Android control usage summary

I hope this article will be helpful to everyone's Android programming design.