If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Developer
tej
Posts: 33
Registered: ‎12-26-2013
My Device: 8760
My Carrier: airtel
Accepted Solution

Blackberry Rotating image

I am kind of new to Blackberry. I have an Image that I need to rotate to certain degree its like compass is there any one who have done this please provide me code or any link.

Regards
Tej

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blackberry Rotating image

Does this help?

 

http://supportforums.blackberry.com/t5/Java-Development/Rotate-and-scale-bitmaps/ta-p/492524

 

You wil find the search facility (See Search box near top right) useful to find things like this for yourself. 

Please use plain text.
Developer
Developer
tej
Posts: 33
Registered: ‎12-26-2013
My Device: 8760
My Carrier: airtel

Re: Blackberry Rotating image

[ Edited ]

@Peter i have tried out this code but showing red blank screen

 

public final class MyScreen extends MainScreen
{
/**
* Creates a new MyScreen object
*/
private Bitmap bitmap = Bitmap.getBitmapResource("img/compass.png");
private BitmapField bitmapField = new BitmapField();
private VerticalFieldManager vfm = new VerticalFieldManager(VerticalFieldManager.USE_ALL_HEIGHT | VerticalFieldManager.USE_ALL_WIDTH) {
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0x660000);
g.clear();
}
};


private int angle = 0;
public MyScreen()
{
// Set the displayed title of the screen
setTitle("MyTitle");
bitmapField.setBitmap(bitmap);
try {
rotateImage(bitmap,90);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
vfm.add(bitmapField);
add(vfm);
}
public static Bitmap rotateImage(Bitmap bitmap, int angle) throws Exception
{
int w = bitmap.getWidth();
int h = bitmap.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];
bitmap.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;
}

}

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blackberry Rotating image

And it works if you don't rotate it?

Please use plain text.
Developer
Developer
tej
Posts: 33
Registered: ‎12-26-2013
My Device: 8760
My Carrier: airtel

Re: Blackberry Rotating image

@peter

 

no actiion even i tried with ImageManipulator class now image is showing but no rotation

 

private Bitmap bitmap = Bitmap.getBitmapResource("img/compass.png");
private ImageManipulator imageManip = new ImageManipulator(bitmap);

Please use plain text.
Developer
Developer
tej
Posts: 33
Registered: ‎12-26-2013
My Device: 8760
My Carrier: airtel

Re: Blackberry Rotating image

is there any one who got working image rotation please help me:Helpsmilie:

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blackberry Rotating image

I think that you can debug this some more yourself and so make it easier for others to help you. 

 

For example, I asked if you had tried it without rotation.  If you test without rotation, this will tell you if the problem is in the rotation code (it works without rotation) or elsewhere in your program (it doesn't work without rotation).  I would also try an image that is not transparent to see if that makes a difference. So can you please do some more analysis yourself and so define the problem a bit more clearly? 

 

And yes I have rotated some images.  That said, the images were not very good when rotated and in the end (since I only wanted to show a set number of rotations), it was better to prepare pre rotated images (which I did using a PC application) and use these.  Depending on what you are doing, you might find the same. 

Please use plain text.
Developer
Developer
tej
Posts: 33
Registered: ‎12-26-2013
My Device: 8760
My Carrier: airtel

Re: Blackberry Rotating image

@peter i have checked with rotation and without rotation code in both condition its not working

 

and if you are takking about image then i dont have idea whicj format that image will work what should

be that height and width i will attach my image which i am testing and like You say u have done some rotation

please send me that code so that i can get some idea.

 

ccompass.png.

what i want is if i am rotate my device 5 degree then this image should also rotate 5 degree.

A:Sweatdrop:ny help will be appreciated:Sweatdrop:

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blackberry Rotating image

As noted I did NOT use rotation.  And I would NOT use rotation in your case either.  If you try to rotate this very detailed image on the BB, it will be slow and it will introduce serious artifacts. 

 

Instead I would use a PC package to rotate the images.  So for example, in this case, create images for 0 degrees, 5 degrees, 10 degrees and so on, i.e. a total of 72 images.  This will give you better images.  Save these images in your application.  Then in your application, all you need do is determine which image is closest to the degree you want to display, then you can display that image.

 

1) "i have checked with rotation and without rotation code in both condition its not working"

 

You should debug this and get the non rotating image working correctly.  There is no point looking at rotation something when the non rotated image is not being displayed is there?  You should be able to debug this without any help - try other images for example to see what happens. 

 

I don't have time to try things for you atm.  Perhaps later.  But you should try to sort this out. 

 

2) "please send me that code"

 

You already have the code I tried.

 

BTW, Please spell check your posts. 

Please use plain text.
New Developer
vnlakshmi39
Posts: 46
Registered: ‎12-16-2013
My Device: 9780 Bold
My Carrier: Airtel

Re: Blackberry Rotating image

[ Edited ]
 
Please use plain text.