Article transferred from: Workshop.
Canvas. drawtext ("www.jcodecraeer.com", X, Y, paint); is the X and Y parameters the coordinates of the center of the specified string? Or the coordinates in the upper left corner? The intuitive impression of this problem should be the coordinates in the upper left corner, but the android processing is a little different. I doubt whether the
I. First, let's talk about the SAVE and restore functions of canvas. This is a very attractive part of canvas.
The ondraw method will pass in a canvas object, which is the canvas you use to draw the visual interface of the control.
In the ondraw method, we often see that the
That's how Android is measured , but a pretty control I just know where you are and that's not going to work. Simply rewrite the OnDraw method and invoke the colorful brush on the canvas (Canvas) object to draw the "sexy" appearance of the control. So how does the view draw?
Implementation and demo of the Android canvas
Today we bring you a simple implementation of the Android canvas function. The following is:
The following are the key source code:
import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.gr
Child View...}protected boolean drawchild (canvas canvas, View child,long drawingtime) {return child.draw (canvas, this, drawingtime);}Description1. When customizing a view, rewrite OnDraw.Calling View.invalidate () will trigger OnDraw and Computescroll (). If the view is attached to the current window view.postinvalidate (); is called on a non-UI thread.2. Cust
Overview:We often encounter features that need to be implemented using paint. For example, some common geometric shapes-points, lines, arcs, circles, ellipses, text, rectangles, polygons, curves, rounded rectangles-can never encounter a geometric figure instead. So our cell phone will certainly be too unbearable. Even if we can now use a few images to solve some of the current problems, these are nothing to say about the "changeable" needs. For this, we can use
Canvas is a very useful concept in graphic programming. There are usually 3 basic components:1.Canvas provides a drawing method to draw basic graphics to the underlying bitmap. (I think it's a good explanation, much better than explaining it as a canvas)2.Paint is called a brush or brush, paint can specify how to
This article describes how to use the android graphics technology to randomly draw a color solid circle. Effect 1 is shown.
Figure 1
the core of the Program is the canvas, that is, the canvas object. To draw a graph on canvas
by calling resource. getdrawable (int id.
The drawable folder supports the following image formats: GIF, PNG, JPG, and BMP.
2.1 Conversion Relationship Between bitmap and drawable
2.1.1 convert bitmap to drawable:
Bitmapdrawable = new bitmapdrawable (Bitmap) Because btimapdrawable is a child class of drawable, bitmapdrawable is used directly.
2.1.2. Convert drawable to bitmap
Refer to method 1.5.3 for obtaining bitmap.
3. Canvas and paint
The
I. First, let's talk about the SAVE and restore functions of canvas. This is a very attractive part of canvas.
The ondraw method will pass in a canvas object, which is the canvas you use to draw the visual interface of the control.
In the ondraw method, we often see that the
(); Try { Bitmap = bitmap. createbitmap (width, height, quality ); Bitmap. setdensity (getresources (). getdisplaymetrics (). densitydpi ); If (autoscale ){ Mdrawingcache = new softreference } Else { Munscaleddrawingcache = new softreference } } Catch (outofmemoryerror e ){ // If there is not enough memory to create the bitmap cache, just // Ignore the issue as bitmap caches are not required to draw // View hierarchy If (autoscale ){ Md
of the same size as the target on the canvas, and then select SRC_IN for xfermode, let's talk about our profile picture or other pictures. You can also draw a graph first and then draw a circle. However, you must select DST_IN for xfermode. Both of them can achieve the desired effect. The sample code is as follows:
Paint p = new Paint (); p. setAntiAlias (true);
same size as the target on the canvas, and then select SRC_IN for xfermode, let's talk about our profile picture or other pictures. You can also draw a graph first and then draw a circle. However, you must select DST_IN for xfermode. Both of them can achieve the desired effect. The sample code is as follows:
Paint p = new Paint ();
P. setAntiAlias (true);
Android font drawing, distance calculation notes, and android draw
Please indicate the source for reprinting. If any error occurs, please point out
Android FontMetrics is defined in the Paint class and has five attributes respectively. To understand this attribute, you can draw
When drawing a dynamic image in the canvas, if a fixed background image is used, only one small genie is moving!
In this case, you have to re-draw the background image without frame, reducing the efficiency! I tried various methods and eventually failed!
If anyone has a good method, please provide it. Thank you!
The following are some examples of the exploration process:
1. An article about redrawing
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.