There is nothing to do recently. I wrote a paintboard demo (sketchpad) and shared it with you.
Function Description:
1. Draw a pen, erase (eraser), and clear (clear ).
2. Undo and redo functions.
3. Save and load the handwriting (stroke ).
4. Paint Brush color.
5. Canvas background color.
6. Paint Brush and rubber size.
7. Select the image.
Please contact me about how source is needed: leehong2005@163.com
First watch:
Graphic board Main Interface
Paint Brush
Rubber
Paint Color
After selecting a color
Paint brushes of different colors and different sizes
Select the background image interface (search for images from sdcard)
Find the image page
After selecting a background image
How to implement it?
Technical points:
1. How to erase strokes and smooth strokes
2. How to save
3. How to draw
4. How to find images in sdcard
5. How to Design undo and redo
6. How to Design the overall architecture
There are too many codes here. I just want to talk about my ideas:
1. Draw a line using path. This is for sure. It is not smooth if only two points are connected. You can use this method:
Path: quadto. How to use it for query? This is a quadratic curve. The painting path specifies a painting. The following items must be specified for the painting line:
m_penPaint.setAntiAlias(true); m_penPaint.setDither(true); m_penPaint.setColor(penColor); m_penPaint.setStrokeWidth(penSize); m_penPaint.setStyle(Paint.Style.STROKE); m_penPaint.setStrokeJoin(Paint.Join.ROUND); m_penPaint.setStrokeCap(Paint.Cap.ROUND);
To draw an eraser, you must specify the following items:
m_eraserPaint.setAntiAlias(true); m_eraserPaint.setDither(true); m_eraserPaint.setColor(0xFF000000); m_eraserPaint.setStrokeWidth(eraserSize); m_eraserPaint.setStyle(Paint.Style.STROKE); m_eraserPaint.setStrokeJoin(Paint.Join.ROUND); m_eraserPaint.setStrokeCap(Paint.Cap.SQUARE); m_eraserPaint.setXfermode(newPorterDuffXfermode(PorterDuff.Mode.DST_OUT));
Note that the red sentence is very important. Do not forget it. You can check the specific modes. For more information, see the com. example. Android. APIs. graphics/xfermodes. Java
2. Painting is directly drawn on the canvas. You can set a bitmap in the canvas to save the bitmap.
3. The rendering process should be ontouch's action_down, action_up, and action_move events.
4. Search for images in sdcard,
ContentResolver cr = context.getContentResolver(); String[] proj = { MediaStore.Video.Media._ID, MediaStore.Video.Media.DISPLAY_NAME, MediaStore.Video.Media.ALBUM, MediaStore.Video.Media.ARTIST, MediaStore.Video.Media.CATEGORY, MediaStore.Video.Media.DESCRIPTION, MediaStore.Video.Media.RESOLUTION, MediaStore.Video.Media.DURATION, }; Uri baseUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI; Cursor c = cr.query(baseUri, proj, null, null, null);
5. Undo and redo
For graphic panels, there is no essential difference between draw lines and draw erasers. Therefore, the graphic board should depend on an abstract object. Therefore, I propose an isketchpadtool interface, which defines
public void draw(Canvascanvas); public boolean hasDraw(); public void cleanAll(); public void touchDown(float x, float y); public void touchMove(float x, float y); public void touchUp(float x, float y);
Paint brushes and erasers implement these interface methods.
Every stroke is regarded as a step. Each step is an interface object of isketchpadtool and put it in a stack. When Undo is used, the elements at the top of the Undo stack are removed, put it in the redo stack and re-draw the rest. The redo process is the opposite.This is my first personal product "uefa.com news client". Please pay attention to it. Thank you.Http://apk.hiapk.com/html/2013/06/1511803.html