Monday, 27 August 2012

Blackberry - Rotate an image in any degree

This BitmapRotation works from Blackberry Version 5.0 on-wards.

Do the following steps:

1. Download the zip file from this link: BitmapRotate at down side.

2. Extract and take the ImageManipulator.java from that add to your project;

3. and use this code from this link: RotatingBitmap on Blackberry;

or

take MY code from the below LINK for rotate an image in BB:

BitmapRotate.zip

Otherwise take this code:

1. Download the zip file from this link: BitmapRotate at down side.

2. Extract and take the ImageManipulator.java from that add to your project;

and then in our code:

================== StartUp.java===================



public class StartUp extends UiApplication
{
public static void main(String[] args)
{
StartUp app = new StartUp();
app.enterEventDispatcher();
}

public StartUp()
{
RotateScreen screen = new RotateScreen();
pushScreen(screen);
}

public static void showAlertMessage(final String message)
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert(message);
}
});
}
}


================ RotateScreen.java=============


public class RotateScreen extends MainScreen
{
private BitmapField bitmapField = new BitmapField();
private Bitmap bitmap = Bitmap.getBitmapResource("simple.png");
private ImageManipulator imageManip = new ImageManipulator(bitmap);
private int angle=0;

private VerticalFieldManager vfm = new VerticalFieldManager(VerticalFieldManager.USE_ALL_HEIGHT | VerticalFieldManager.USE_ALL_WIDTH)
{
protected void paintBackground(Graphics g)
{
g.setBackgroundColor(Color.GREEN);
g.clear();
}
};
public RotateScreen()
{
super(MainScreen.HORIZONTAL_SCROLLBAR | MainScreen.VERTICAL_SCROLLBAR);
bitmapField.setBitmap(bitmap);
vfm.add(bitmapField);
add(vfm);
addMenuItem(new Restore());
addMenuItem(new Rotate());
addMenuItem(new Continuous());
}

private class Restore extends MenuItem
{
public Restore()
{
super("Restore", 0, 100);
}
public void run()
{
try {
angle = 0;
imageManip.resetTransform();
bitmapField.setBitmap(imageManip.transformAndPaintBitmap());
invalidate();
} catch (Exception e) {
StartUp.showAlertMessage(e.toString());
}

}
}

private class Rotate extends MenuItem {
public Rotate() {
super("Rotate", 0, 100);
}

public void run()
{
try
{
angle +=90;
imageManip.transformByAngle(angle, false, false);
bitmapField.setBitmap(imageManip.transformAndPaintBitmap());
invalidate();
}
catch (Exception e)
{
StartUp.showAlertMessage(e.toString());
}
}
}

private class Continuous extends MenuItem {
public Continuous()
{
super("Continuous", 0, 100);
}

public void run()
{
try
{
new Thread()
{
public void run()
{
for (int angle = 1; angle <= 360; angle++)
{
imageManip.transformByAngle(angle, false, false);
synchronized (UiApplication.getEventLock())
{
bitmapField.setBitmap(imageManip.transformAndPaintBitmap());
invalidate();
}
try
{
Thread.sleep(500);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
}.start();

} catch (Exception e) {
StartUp.showAlertMessage(e.toString());
}

}
}
}

See the below Screen shots:







1 comment:

  1. The nice code written on this blog that helpful for me or other people who want to rotate an image on the Blackberry.So thanks for giving this.

    Mobile App Development

    ReplyDelete