Android Multimedia Development Learn to make a simple artboard

Source: Internet
Author: User
<span id="Label3"></p><p><p>A simple artboard that can be drawn, can be selected for color, can be saved. of course, this kind of tools commonly used communication software will be there, such as qq, flying autumn, etc.</p></p><p><p>Where we have to monitor finger touch events, finger touch events are divided into 3 kinds: press, lift, Move. Usually we just need the relationship pressed, and then the whole finger sliding process. Then the process of swiping the finger is drawn as a different line. of course, you can set the drawing color, draw the line width, etc.</p></p><p><p><br></p></p><p><p></p></p><pre name="code" class="java">public class Mainactivity extends Activity {private int touchx;private int touchy;private Paint paint;private Canvas Canva S Bitmap Bitmapcopy;imageview lview; @Override protected void onCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); 1: first create a background picture of the artboard, this time the picture needs to be modified, you need to create a copy of the picture Bitmap bitmapsrc = Bitmapfactory.decoderesource (getresources (), r.drawable . bg); Bitmapcopy = Bitmap.createbitmap (bitmapsrc.getwidth (), bitmapsrc.getheight (), bitmapsrc.getconfig ()); Paint = new Paint (); Canvas = new Canvas (bitmapcopy); Canvas.drawbitmap (bitmapsrc, new Matrix (), paint); LView = (ImageView) Findviewbyid (r.id.lv); Lview.setimagebitmap (bitmapcopy); 2: Touch Event Lview.setontouchlistener (new ontouchlistener () {@Overridepublic boolean onTouch (View v, motioneve NT Event) {//finger touch three kinds of: press, lift, move int action = Event.getaction (Switch (action) {case Motionevent.action_down://first is pressed, when pressed, you need to record the first pressed position Touchx = (int) Event.getx (); Touchy = (int) event.gety (); break;case motionevent.action_move://as long as each move, will produce a moving event, get the current coordinates int x = (int) Event.getx (); int y = (int) event.gety ();//draw line canvas.drawline (touchx, touchy, x, y, paint);//change The starting coordinate of the next draw Touchx = x; Touchy = Y;lview.setimagebitmap (bitmapcopy); break;case MotionEvent.ACTION_UP:break;} True: tell the system that this touch event is handled by Me//false: tell the system that this touch event I do not handle, then the system will pass the touch event to Imageview's parent node return true;}); }//sets the color of the brush to red public void red (View v) {paint.setcolor (color.red); }//sets the color of the brush to green public void green (View V) {paint.setcolor (color.green); }//set the width of the brush public void brush (View v) {paint.setstrokewidth (7); }//save public void Save (View v) {file file = new file ("sdcard/tupian.png"); FileOutputStream fstream = null; Try {fstream = new FileOutputStream (file),} catch (filenotfoundexception e) {//TODO auto-generated catch blocKe.printstacktrace ();} Saved in PNG format, 100 represents the highest quality bitmapcopy.compress (compressformat.png, fstream); }}</pre><p><p></p></p><p><p><br></p></p>The above is a simple artboard, you can draw a simple picture, can be saved.<p><p><br><br></p></p><p><p><br></p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>Android Multimedia Development Learn to make a simple artboard</p></p></span>

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.