The examples in this article describe the approach to the Android image processing. Share to everyone for your reference, specific as follows:
Package cn.szbw.util;
Import Android.content.Context;
Import Android.graphics.Bitmap;
Import Android.graphics.BitmapFactory;
Import Android.graphics.Canvas;
Import Android.graphics.Matrix;
Import Android.graphics.Paint;
public class Utils {/*** * loading local picture * @param context: Main Run function instance * @param bitadress: Picture address, General point R drawable Directory * @return/public final Bitmap creatimage (context, int bitadress) {Bitmap bitmaptemp = Nu
ll
Bitmaptemp = Bitmapfactory.decoderesource (Context.getresources (), bitadress);
return bitmaptemp; //2. Image average Segmentation method, the large image is divided into n rows n columns, to facilitate users to use/*** * Image segmentation * @param g *: Canvas * @param paint *: Brushes * @p
Aram Imgbit *: Picture x *:x axis start coordinate * @param y *:y Axis Start coordinate * @param w *: Width of single picture * @param h *: The height of a single picture * @param line *: A few columns * @param row *: The first few lines/public final void Cuteimage (Canvas g
, Paint 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. Picture scaling, scaling the current picture/*** * Image Scaling Method * * @param bgimage *: Source Picture Resource * @param newwidth *: Zoom width * @param newheight *: Zoom Height * @return/public Bitmap zoomimage (Bitmap bgimage, int newwidth, int ne
Wheight) {//Get the width and height int width = bgimage.getwidth () of this picture;
int height = bgimage.getheight ();
Matrix matrix for creating an action picture matrix = new Matrix ();
Calculate the scaling rate, the new size in addition to the original size float ScaleWidth = ((float) newwidth)/width;
float ScaleHeight = ((float) newheight)/height;
Zoom picture Action Matrix.postscale (ScaleWidth, ScaleHeight);
Bitmap Bitmap = Bitmap.createbitmap (bgimage, 0, 0, width, height, matrix, true);
return bitmap; //4. Draw text with borders, generally play the role of text in the game/** * Draw text with Border * @Param STRMSG *: Drawing content * @param g *: Canvas * @param paint *: Brush * @param setx *:x Axis start coordinates * @param the starting coordinates of the sety *:y axis * @param FG *: foreground color * @param BG *: Background color/public void DrawText (Strin
G STRMSG, Canvas G, Paint 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 ();
}
}
For more information on Android-related content readers can view the site: "Android graphics and image processing skills summary", "Android Development introduction and Advanced Course", "Android debugging techniques and common problems solution summary", " Android Multimedia How-to Summary (audio, video, audio, etc), summary of Android Basic components usage, Android View tips Summary, Android layout layout tips and a summary of Android controls usage
I hope this article will help you with the Android program.