I used this way for rotating a bitmap image. But it is redusing the image quality on each rotation. Can any one suggest a better way ?
Code:
public static Bitmap rotateImage(Bitmap oldB, int angle) throws Exception
{
int w = oldB.getWidth();
int h = oldB.getHeight();
double angRad = (angle % 360)*(Math.PI/180);
Bitmap newB = new Bitmap(w,h);
int[] oldD = new int[w*h];
int[] newD = new int[w*h];
oldB.getARGB(oldD, 0, w, 0, 0, w, h);
int axisX = w/2;
int axisY = h/2;
for(int x = 0; x < oldD.length; x++)
{
int oldX = x%w;
int oldY = x/w;
int op = oldX-axisX;
int adj = oldY-axisY;
double oldT = MathUtilities.atan2(op, adj);
double rad = Math.sqrt((op*op)+(adj*adj));
double newT = oldT+angRad;
int newX = (int)MathUtilities.round((rad*Math.sin(newT))+(double)axisX);
int newY = (int)MathUtilities.round((rad*Math.cos(newT))+(double)axisY);
if(newX<0||newY<0||newX>=w||newY>=h)
{
newD[x] = 0x00000000;
}
else
{
newD[x] = oldD[(newY*w)+newX];
}
}
newB.setARGB(newD, 0, w, 0, 0, w, h);
return newB;
}
My problem describes below.
1. I have some bytes of image.
2. I want to rotate image by 90 degree.
3. I want to keep aspect ration , and need image as bytes in back.
Here I used PngEncodedImage api for retrieving Bitmap to byte[] . But its making poor quality image.
Pleas suggest ..!!