Android camera angle chart

Source: Internet
Author: User

Package com. cardroid. layer;
Import Android. content. context;
Import Android. Graphics. Bitmap;
Import Android. Graphics. bitmapfactory;
Import Android. Graphics. camera;
Import Android. Graphics. Canvas;
Import Android. Graphics. matrix;
Import Android. View. motionevent;
Import Android. View. view;

Public class cameradraw extends view {

Private context;
Private bitmap showbmp;
Private matrix; // Action Matrix
Private camera;
Private int deltax, deltay; // flip angle difference
Private int centerx, centery; // image center point

Public cameradraw (context ){
Super (context );
This. Context = context;
Initdata ();
}

Private void initdata (){
Showbmp = bitmapfactory. decoderesource (context. getresources (), R. drawable. bg );
Centerx = showbmp. getwidth ()/2;
Centery = showbmp. getheight ()/2;
Matrix = new matrix ();
Camera = new camera ();
}

Int lastmousex;
Int lastmousey;
@ Override
Public Boolean dispatchtouchevent (motionevent event ){
Int x = (INT) event. getx ();
Int y = (INT) event. Gety ();
Switch (event. getaction ()){
Case motionevent. action_down:
Lastmousex = X;
Lastmousey = y;
Break;
Case motionevent. action_move:
Int dx = x-lastmousex;
Int DY = Y-lastmousey;
Deltax + = DX;
Deltay + = Dy;
Break;
}

Invalidate ();
Return true;
}

@ Override
Protected void ondraw (canvas ){

Camera. Save ();
// Flip around the X axis
Camera. rotatex (-deltay );
// Flip around the Y axis
Camera. rotatey (deltax );
// Sets the camera role matrix.

Camera. getmatrix (matrix );
Camera. Restore (); // mainly obtains the size of the flip matrix.
// Set the flip Center
Matrix. pretranslate (-This. centerx,-This. centery );
Matrix. posttranslate (this. centerx, this. centery );

Canvas. drawbitmap (showbmp, matrix, null );
}

}

Public class layerdraw extends activity {
/** Called when the activity is first created .*/
Private imageview mimageview;
Private textview tview;
Private cameradraw carmeracameradraw;
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Carmeracameradraw = new cameradraw (this );
// Setcontentview (R. layout. Main );
Setcontentview (carmeracameradraw );
// Mimageview = (imageview) findviewbyid (R. Id. Image );
// Tview = (textview) findviewbyid (R. Id. TV );
// Setimage ();
}

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.