Perform the Drawing operation on the camera preview of Android

Source: Internet
Author: User

From anddev

Import android. app. activity; import android. content. context; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. hardware. camera; import android. OS. bundle; import android. view. surfaceholder; import android. view. surfaceview; import android. view. view; import android. view. window; import android. view. viewgroup. layoutparams; public class testcameraoverlay extends activity {/** called when the activity is first created. * // @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); requestwindowfeature (window. feature_no_title); preview mpreview = new Preview (this); drawontop mdraw = new drawontop (this); setcontentview (mpreview); addcontentview (mdraw, new layoutparams (layoutparams. wrap_content, layoutparams. wrap_content) ;}} class drawontop extends view {public drawontop (context) {super (context ); // todo auto-generated constructor stub} @ override protected void ondraw (canvas) {// todo auto-generated method stub paint = new paint (); paint. setstyle (paint. style. fill); paint. setcolor (color. black); canvas. drawtext ("test text", 10, 10, paint); super. ondraw (canvas) ;}} class preview extends surfaceview implements surfaceholder. callback {surfaceholder mholder; camera mcamera; Preview (context) {super (context); // install a surfaceholder. callback so we get notified when the // underlying surface is created and destroyed. mholder = getholder (); mholder. addcallback (this); mholder. settype (surfaceholder. surface_type_push_buffers);} public void surfacecreated (surfaceholder holder) {// The surface has been created, acquire the camera and tell it where // to draw. mcamera = camera. open (); mcamera. setpreviewdisplay (holder);} public void surfacedestroyed (surfaceholder holder) {// surface will be destroyed when we return, so stop the preview. // because the cameradevice object is not a shared resource, it's very // important to release it when the activity is paused. mcamera. stoppreview (); mcamera = NULL;} public void surfacechanged (surfaceholder holder, int format, int W, int h) {// now that the size is known, set up the camera parameters and begin // the preview. camera. parameters = mcamera. getparameters (); parameters. setpreviewsize (W, H); mcamera. setparameters (parameters); mcamera. startpreview () ;}} parsed in 0.113 seconds, using geshi 1.0.8.4

Related Article

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.