I have one png image.
Then, I want to flip this triangle as on the next image.
Red region it is our original image which is reflected and turned. And then I want to rotate new region (red region) on different angles.
How can i do it in android?
Thanks in advance!
To rotate an image in android you should look here
Rotate image in android
Or here
Android: Rotate image in imageview by an angle
To get a mirror image of your PNG, do this (taken from the link below, from Dalmas's answer)
Matrix matrix = new Matrix();
matrix.preScale(-1.0f, 1.0f);
Bitmap mirroredBitmap = Bitmap.createBitmap(bmp, 0, 0, bmp.width(), bmp.height(), matrix, false);
How to mirror an image file? (2.2+)
To rotate a vector look here
Rotating a vector using Matrix.rotateM
Related
I have bitmap which i mirror using the matrix
mMirror.postScale(-1.0f, 1.0f);
and can "un-mirror" using
mMirror.postScale(1.0f, 1.0f);
However,now when I rotate the bitmap using mRRight.postRotate(90) , the mirroring is lost.Why?
EDIT
Figured a part of the answer for the.When you create a Bitmap object,an Identity matrix is used and created internally which corrects all the mirroring etc.
Now the question changes to how do I Mirror and then rotate a matrix.
I am working on a project where I need to ZoomIn and rotate the image simultaneously on seekbar progress value.
I have tried below code. But this is not working. This is just rotating the image.
Matrix matrix = new Matrix();
matrix.postRotate(curValue);
//matrix.postScale(curValue, curValue);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmaprotate, 0, 0, bmpWidth, bmpHeight, matrix, true);
mainImage.setImageBitmap(resizedBitmap);
For achieving this you better to use custom view and canvas. Using canvas you can easily rotate and scale the images. Please refer this links (resize the bitmap canvas ,Android Scaling Canvas Bitmap , http://www.barebonescoder.com/2010/06/android-development-simple-2d-graphics-part-1/)
I'm using the matrix.rotate(deg, fx,fy) method to rotate an image.
The image has an alpha channel and only has something visual in the right-hand corner. I want to rotate the canvas, create the new image with that matrix and have the visual part be the only part that is rotating.
At the moment the image rotates but doesn't rotate around the desired axis. It always rotates around the original width of the object.
Here is the code I use:
Matrix matrix = new Matrix();
matrix.setRotate(rotation, xPivot, yPivot);
Bitmap pic1a = Bitmap.createBitmap(pic1, 0, 0, pic1.getWidth(), pic1.getHeight(), matrix, true);
This rotates the image correctly but only seems to rotate within the same location of the original canvas.
What I want is for the point that the image rotates around (xPivot, yPivot) becoming the centre location on the display.
I'm drawing a bunch of icons on a map. Actually the icons come from the same image rotated. But on the map the images take on two different sizes, I don't know why. This is what the result looks like: http://orangesoftware.net/iconmap.png
The image file looks like this: http://orangesoftware.net/arrow18.png
The code to rotate the icon:
Matrix mtx = new Matrix();
mtx.postRotate(unit.heading);
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.arrow18);
Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),
bmp.getHeight(), mtx, true);
BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);
Any magically insights appreciated, thanks
The cause of the variation in sizes is when a rotation is not a multiple of 90 degrees. The bmp becomes a diamond who's corners stick out beyond the ImageView holding it, thus it gets resized to fit the ImageView.
The easiest way to take care of this discrepancy is to set the ImageView's scaleType to CENTER. This will simply center the image inside without scaling it to fit.
I am new to OpenGl and needed some help.
I have a screen was able to draw a imageon it. Now i want to create a mirror image of the same image i.e i want the screen to be divided in 2 parts(horizontally) and then have the actual image at the bottom and create a duplicate image at the top just like a mirror image so that if a change is made to the bottom image it reflects on the top image too.
Please give suggestions. (I do not want canvas mirror image code)
try this
sprite = BitmapFactory .decodeResource(appContext.getResources(),R.drawable.spritegfx);
Matrix temp1=new Matrix();
temp1.preScale(-1.0f,1.0f);
flipedSprite = Bitmap.createBitmap(sprite , 0, 0,sprite.getWidth(),sprite .getHeight(), temp1, false);
canvas.drawBitmap(flipedSprite , 0,0, null);
http://www.opengl.org/archives/resources/faq/technical/transformations.htm#tran0170