×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Regular Contributor
    Join Date
    Jun 2009
    Location
    London
    Posts
    50

    Question Vertically flip an image

    Is there a way to mirror (vertically flip) an image? I saw that you can do that using Sprites

    PHP Code:
    Sprite mySprite = new Sprite(imgimg.getWidth(), img.getHeight());
    mySprite.setTransform(Sprite.TRANS_MIRROR_ROT180); 
    but I don't know how to get the flipped image back

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Vertically flip an image

    Quote Originally Posted by polys View Post
    Is there a way to mirror (vertically flip) an image? I saw that you can do that using Sprites

    PHP Code:
    Sprite mySprite = new Sprite(imgimg.getWidth(), img.getHeight());
    mySprite.setTransform(Sprite.TRANS_MIRROR_ROT180); 
    but I don't know how to get the flipped image back
    Take two sprites, one which is the mirror image and rest other one is original.

    Or try to set the transform as the Sprite.TRANS_MIRROR_ROT180 one more time, this you have to check by setting the various one,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Regular Contributor
    Join Date
    Jun 2009
    Location
    London
    Posts
    50

    Re: Vertically flip an image

    Quote Originally Posted by raj_J2ME View Post
    Take two sprites, one which is the mirror image and rest other one is original.

    Or try to set the transform as the Sprite.TRANS_MIRROR_ROT180 one more time, this you have to check by setting the various one,
    Raj, thanks for your reply.

    The mirror image doesn't exist. There is only one image, the original, which I want to flip vertically. If I do this:

    PHP Code:
    Sprite mySprite = new Sprite(imgimg.getWidth(), img.getHeight());
    mySprite.setTransform(Sprite.TRANS_MIRROR_ROT180); 
    does the object "img" get mirrored? Or does this create a sprite with the mirrored image?

  4. #4
    Regular Contributor
    Join Date
    May 2007
    Location
    India
    Posts
    208

    Re: Vertically flip an image

    Quote Originally Posted by polys View Post
    Raj, thanks for your reply.

    The mirror image doesn't exist. There is only one image, the original, which I want to flip vertically. If I do this:

    PHP Code:
    Sprite mySprite = new Sprite(imgimg.getWidth(), img.getHeight());
    mySprite.setTransform(Sprite.TRANS_MIRROR_ROT180); 
    does the object "img" get mirrored? Or does this create a sprite with the mirrored image?
    The img will remain as it is. The rendering appearance of the sprite changes only.

  5. #5
    Regular Contributor
    Join Date
    Jun 2009
    Location
    London
    Posts
    50

    Re: Vertically flip an image

    Quote Originally Posted by gaurav007 View Post
    The img will remain as it is. The rendering appearance of the sprite changes only.
    So how do I mirror the img? I don't need a sprite anyway. All I want is to mirror the img.

  6. #6
    Regular Contributor
    Join Date
    May 2007
    Location
    India
    Posts
    208

    Re: Vertically flip an image

    Quote Originally Posted by polys View Post
    So how do I mirror the img? I don't need a sprite anyway. All I want is to mirror the img.
    Could you elaborate the purpose behind it. Do you want to save the transformed image on device memory using FC API?

  7. #7
    Regular Contributor
    Join Date
    Jun 2009
    Location
    London
    Posts
    50

    Re: Vertically flip an image

    Quote Originally Posted by gaurav007 View Post
    Could you elaborate the purpose behind it. Do you want to save the transformed image on device memory using FC API?
    I just want to display the transformed image on the screen. I don't want to save it on the device.

    So all i need is:

    originalImage (which I already have) --> mirroredImage --> display mirroredImage

  8. #8
    Regular Contributor
    Join Date
    May 2007
    Location
    India
    Posts
    208

    Re: Vertically flip an image

    Quote Originally Posted by polys View Post
    I just want to display the transformed image on the screen. I don't want to save it on the device.

    So all i need is:

    originalImage (which I already have) --> mirroredImage --> display mirroredImage
    I've never tried this but the possible way is by using the setTransform method of Sprite class. use it to rotate the image. Now create a mutable image of same dimension and using getGraphics get its graphics object. pass this graphics object into paint method of sprite and it should draw the rotated image on the mutable image.

    Let me know if this serve your purpose.

  9. #9
    Regular Contributor
    Join Date
    Jun 2009
    Location
    London
    Posts
    50

    Re: Vertically flip an image

    Quote Originally Posted by gaurav007 View Post
    I've never tried this but the possible way is by using the setTransform method of Sprite class. use it to rotate the image. Now create a mutable image of same dimension and using getGraphics get its graphics object. pass this graphics object into paint method of sprite and it should draw the rotated image on the mutable image.

    Let me know if this serve your purpose.
    I did this, which only draws a black line on the screen. Don't know if it draws only "part" of the flipped image for some reason.

    PHP Code:
    Image flippedImg Image.createImage(imgWidthimgHeight);

    // Get graphics object to draw onto the image
    Graphics flippedGraphics flippedImg.getGraphics();

    Sprite mySprite = new Sprite((javax.microedition.lcdui.Image)im.getImage(), imgWidthimgHeight);
    mySprite.setTransform(Sprite.TRANS_MIRROR_ROT180);
    mySprite.paint(flippedGraphics); 
    FYI: the original image is a LWUIT image because I create it using the LWUIT bitmap fonts. That's why I do (javax.microedition.lcdui.Image)im.getImage()

  10. #10
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Vertically flip an image

    If its a LWUIT Image, just use com.sun.lwuit.Image.rotate

    rotate
    public Image rotate(int degrees)Returns an instance of this image rotated by the given number of degrees. By default 90 degree angle divisions are supported, anything else is implementation dependent. This method assumes a square image. Notice that it is inefficient in the current implementation to rotate to non-square angles,
    E.g. rotating an image to 45, 90 and 135 degrees is inefficient. Use rotatate to 45, 90 and then rotate the 45 to another 90 degrees to achieve the same effect with less memory.


    Parameters:
    degrees - A degree in right angle must be larer than 0 and up to 359 degrees
    Returns:
    new image instance with the closest possible rotation

    Rotate the 10 degree at a time, sleep(100) and repaint() it again and again to see the effect.

    thanks,
    ~Amitabh

  11. #11
    Regular Contributor
    Join Date
    Jun 2009
    Location
    London
    Posts
    50

    Re: Vertically flip an image

    Quote Originally Posted by im2amit View Post
    If its a LWUIT Image, just use com.sun.lwuit.Image.rotate

    rotate
    public Image rotate(int degrees)Returns an instance of this image rotated by the given number of degrees. By default 90 degree angle divisions are supported, anything else is implementation dependent. This method assumes a square image. Notice that it is inefficient in the current implementation to rotate to non-square angles,
    E.g. rotating an image to 45, 90 and 135 degrees is inefficient. Use rotatate to 45, 90 and then rotate the 45 to another 90 degrees to achieve the same effect with less memory.


    Parameters:
    degrees - A degree in right angle must be larer than 0 and up to 359 degrees
    Returns:
    new image instance with the closest possible rotation

    Rotate the 10 degree at a time, sleep(100) and repaint() it again and again to see the effect.

    thanks,
    ~Amitabh
    I don't want to rotate the image.

    I want to flip it vertically (mirrored)

    This is the original image:

    http://img651.imageshack.us/img651/4007/originaldb.jpg

    This is the desired outcome:

    http://img186.imageshack.us/img186/1175/flippedt.jpg

  12. #12
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Vertically flip an image

    See the mirror method of LWUIT API for this.


    mirror
    public Image mirror()Deprecated. this method is no longer supported due to issues when mixing it with other methods such as rotate. Future versions of the API will provide an alternative

    Returns a mirror instance of this image

    Returns:
    a mirror instance of this image


    thanks,
    ~Amitabh

  13. #13
    Regular Contributor
    Join Date
    Jun 2009
    Location
    London
    Posts
    50

    Re: Vertically flip an image

    Quote Originally Posted by im2amit View Post
    See the mirror method of LWUIT API for this.


    mirror
    public Image mirror()Deprecated. this method is no longer supported due to issues when mixing it with other methods such as rotate. Future versions of the API will provide an alternative

    Returns a mirror instance of this image

    Returns:
    a mirror instance of this image


    thanks,
    ~Amitabh
    there is no mirror method in the LWUIT

  14. #14
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Vertically flip an image

    You need to flip vertically, i.e. you need 180 degree clockwise rotation try it, which can done by LWUIT rotate directly.

    thanks,
    ~Amitabh

  15. #15
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Vertically flip an image

    Please check this code

    Code:
    public static Image rotateImage(Image image, int angle) throws Exception
    {
    	if(angle == 0)
    	{
    		return image; 
    	}
    	else if(angle != 180 && angle != 90 && angle != 270)
    	{
    		throw new Exception("Invalid angle");
    	}
     
    	int width = image.getWidth();
    	int height = image.getHeight();
     
    	int[] rowData = new int[width];
    	int[] rotatedData = new int[width * height];
     
    	int rotatedIndex = 0;
     
    	for(int i = 0; i < height; i++)
    	{
    		image.getRGB(rowData, 0, width, 0, i, width, 1);
     
    		for(int j = 0; j < width; j++)
    		{
    			rotatedIndex = 
    				angle == 90 ? (height - i - 1) + j * height : 
    				(angle == 270 ? i + height * (width - j - 1) : 
    					width * height - (i * width + j) - 1
    				);
     
    			rotatedData[rotatedIndex] = rowData[j];
    		}
    	}
     
    	if(angle == 90 || angle == 270)
    	{
    		return Image.createRGBImage(rotatedData, height, width, true);
    	}
    	else
    	{
    		return Image.createRGBImage(rotatedData, width, height, true);
    	}
    }
    Here's a sample usage on how to use the rotateImage() method:
    Code:
    Image original = Image.createImage("/original_image.png");
     
    Image rotated_image = rotateImage(original, 90);
    Please check the im2amit's advice for the LWUIT API. Though you can test this method I am sure that this can help you,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. J2ME Scaling big JPEG files on S60 5th ed and CS001269
    By m1ha3l in forum Mobile Java Media (Graphics & Sounds)
    Replies: 14
    Last Post: 2010-04-06, 07:05
  2. Image attribute in Bluetooth ServiceRecord
    By lampz in forum Mobile Java Networking & Messaging & Security
    Replies: 7
    Last Post: 2008-02-18, 20:30
  3. AknIconUtils is caching the image
    By Tatanka.nbr1 in forum Symbian
    Replies: 12
    Last Post: 2007-01-05, 19:08
  4. Image on a Form
    By ionutianasi in forum Mobile Java General
    Replies: 2
    Last Post: 2006-10-24, 11:04
  5. image failed to load
    By killarkai in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2003-07-25, 13:07

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×