Wednesday, April 9, 2014

Matrix conducted on the use of image rotation problems


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);

When using the above code rotate the picture, the picture size changes, and how to make pictures just rotating the same size?

this.imageView: pictures corresponding ImageView object
degree: The angle of rotation
this.w: the width of the original picture
the height of the original picture: this.h
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
 
Bitmap tmpBitmap = Bitmap.createBitmap (this.bitmap, 0, 0, bitmap.getWidth (), bitmap.getHeight (), matrix, true);


Rotate the picture when using the width and height of the image itself set the rotation! !
Reply:
cited a floor xys289187120 reply:
Java code

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



Rotate the picture when using the width and height of the image itself set the rotation! !


this.w and this.h is the original image width with high
Reply:
cited a floor xys289187120 reply:
Java code


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



Rotate the picture when using the width and height of the image itself set the rotation! !


+1
Reply:
reference to the third floor qiying1988 reply:
cited a floor xys289187120 reply:
Java code


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



Rotate the picture when using the width and height of the image itself set the rotation! !


+1


Size or will change
Reply:
this.w, this.h how the value of,
With bitmap.getWidth ()
Reply:
references, 5th Floor archko reply:
this.w, this.h how the value of,
With bitmap.getWidth ()


Yes
Reply:
In addition to the vertical / horizontal rotation (90, 180, ...), after returning with Matrix pictures always turn becomes large, the center unchanged

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


Reply:
reference to the 7th floor edward9145 reply:
addition to rotating vertical / horizontal (90, 180, ...), with Matrix after pictures always turn to return becomes large, the center unchanged

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


I am using a circular picture, there is no way that it does not change the size?
Reply:
There will not be rounded picture ... because the background is transparent so looked round, in fact, the figure is a square, so 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 =? / / The count of his hands under the bar
int y =? / / The count of his hands 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);

Reply:
reference to the 9th floor edward9145 reply:
not have rounded picture ... because the background is transparent so looked round, in fact, is square map, 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 =? / / The count of his hands under the bar
int y =? / / The count of his hands under the bar
int width ......


x, y how counted, can give ideas, I tried several algorithms will not work
Reply:
I have encountered this problem, you kind of logic is wrong, you can not rotate Bitmap, you have to try to rotate canvas, this does not waste memory, do not intercept Pictures
Reply:
Also encountered this problem how to solve?
Reply:
More recently, to study this problem, I use the canvas rotation, but the picture is not in the center column rotation. . .
Reply:
The landlord can do so
You get a new rebitmap
This time you have changed
Width Height
When you canvas.drawBitmap (); time to get a picture with your new width and height rebitmap. getwidth () / 2

No comments:

Post a Comment