BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 09-01-2009, 09:31 AM   #1 (permalink)
New Member
 
Join Date: Jun 2008
Model: 8100
PIN: N/A
Carrier: Airtel
Posts: 6
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default How to rotate imege in many angles.

Please Login to Remove!

Hi All,

I am trying to rotate image in many angles, just like cd rotation.
Please give me suggestion to do this.

I got some methods like drawTexturedPath-

int displayWidth = Display.getWidth();
int displayHeight = Display.getHeight();
int[] x = new int[] { 0, displayWidth, displayWidth, 0 };
int[] x = new int[] { 0, 0, displayHeight, displayHeight };
int angle = Fixed32.toFP( 45 );
int dux = Fixed32.cosd(angle );
int dvx = -Fixed32.sind( angle );
int duy = Fixed32.sind( angle );
int dvy = Fixed32.cosd( angle );
graphics.drawTexturedPath( x, y, null, null, 0, 0, dvx, dux, dvy, duy, image);




But not able to rotate image in a single point with different angle.

Please reply.

Thanks a lot in advace.
Offline  
Old 01-27-2010, 01:38 AM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2008
Location: India
Model: 9000
Carrier: AirTel
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

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 ..!!
__________________
Praveen K
Offline  
Old 02-03-2010, 01:46 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2008
Location: India
Model: 9000
Carrier: AirTel
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Anyone there ?

While using the above method , iam geting issue with big images. If we are rotating images with size more than 30 kb size , its adding some black areas around the width.

How can i have a complete image rotator ?
__________________
Praveen K
Offline  
Old 03-06-2010, 10:43 PM   #4 (permalink)
New Member
 
Join Date: Mar 2010
Model: sa
PIN: N/A
Carrier: asd
Posts: 1
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would save the images somewhere at an angle just how I wanted, then load them into a quality rotator from there. Look up Complete Image Rotator from Mooonbaby into a search. Like I have one of those Complete Image rotators from there and loading any images and more into those work great.
Offline  
Old 03-25-2010, 02:58 AM   #5 (permalink)
New Member
 
Join Date: Mar 2010
Model: 9530
PIN: N/A
Carrier: test
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi to all,
how to use above coding i'm getting MathUtilities error did u use any userdefined function?
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.