2013年9月1日星期日

Android About using the Matrix for picture rotation issue

this.degree + = degree;

Matrix matrix = new Matrix ();
matrix.setRotate (this.degree);

Bitmap tmpBitmap = Bitmap.createBitmap (this.bitmap, 0, 0, this.w, this.h, matrix, true) ;
BitmapDrawable bitmapDrawable = new BitmapDrawable (tmpBitmap);
this.imageView.setImageDrawable (bitmapDrawable);

Using the above code rotate the picture, the picture size changes, and how to make picture rotation only constant size?

this.imageView: ImageView object corresponding picture
degree: The angle of rotation
this.w: the width of the original picture
this.h: Original picture height
------ Solution ---------------------------- ----------------

        Bitmap tmpBitmap = Bitmap.createBitmap( this.bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true );


rotate the picture at the same time set the width and height of the image itself rotates! !
------ Solution ---------------------------------------- ----


+1
------ Solution ---------------------------------- ----------
this.w, this.h how the value of,
with bitmap.getWidth ()
------ Solution ------------------------------ --------------
addition to the vertical / horizontal rotation (90, 180, ...), with the Matrix pictures always turn to go back and become large, center unchanged

For rectangular picture: tmpBitmap.getWidth () ==
bitmap.getWidth () * Math.cos (degree) + bitmap.getHeight () * Math.sin (degree);


------ Solution ------------------------------------ --------
not have rounded picture ... because the background is transparent so looked round, in fact, the figure is a square, so that h == w
Bitmap tmpBitmap = Bitmap.createBitmap (this.bitmap, 0, 0, this.w, this.h, matrix, true) ;
/ / the picture cut out on the line
int x =? / / This hand count yourself under the bar
int y =? / / This hand count yourself under the bar
int width = bitmap.getWidth ();
int height = bitmap.getHeight ();
Bitmap tmpSliceBitmap = Bitmap.createBitmap (tmpBitmap, x, y, width, height)


BitmapDrawable bitmapDrawable = new BitmapDrawable (tmpSliceBitmap);
this.imageView.setImageDrawable (bitmapDrawable);

------ reference ------------------------------------ ---


this.w and this.h is the width of the original picture with high
------ reference ---------------------- -----------------


size will still vary
------ reference -------------------------------- -------


Yes
------ reference ---------------------------------- -----


I am using a circular picture, there is no way that it does not change the size?
------ reference --------------------------------------- < br>

x, y how counted, can give ideas, I tried several algorithms will not
------ reference --------------- ------------------------
I also encountered this problem, you kind of logic is wrong, can not rotate Bitmap, you have to try Rotate canvas, this does not waste memory, do not picture the interception
------ reference -------------------------- -------------
also encountered this problem how to solve?
------ reference --------------------------------------- < br> also recently studied this problem, I use the canvas rotation, but the picture is not in the center column rotation. . .

没有评论:

发表评论