×

Discussion Board

Results 1 to 8 of 8

Thread: Clipping

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    45

    Question Clipping

    Hello Friends,


    Can anybody pls explain how a particular part of an image in png format can be clipped using clipping. Pls also give me the links so that i can refer to that example and understand how can an image be clipped by giving the co-ordinates.

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Clipping

    Two ways to do this.

    Let's say we want to draw part of image img, of width by height pixels, with the top-left corner at (ix,iy) in the image, onto the screen at (sx,sy).

    Method one (MIDP-2.0 and later only):

    Code:
    g.drawRegion(img, ix, iy, width, height, Sprite.TRANS_NONE, sx, sy, Graphics.TOP | Graphics.LEFT);
    Method two (MIDP-1.0 compatible):

    Code:
    g.setClip(sx, sy, width, height);
    g.drawImage(img, sx - ix, sy - iy, Graphics.TOP | Grapics.LEFT);
    If you use method two remember that, once you've changed the clip region, you need to change again later, as it will apply to all operations from then on.

    Graham.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    45

    Re: Clipping

    In method one what that "Sprite.TRANS_NONE" is for. Actually i came to know that it doesnt move anything here but why it is included in the syntax. What that sprite does in the syntax here. Pls explain me.

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    45

    Re: Clipping

    Actually i m developing a game where there is a map in which i have to take every map parts differently and now i hav to join them but since i have arranged them in particular rectangular format i m not able to join them properly and so wat could b done for it.

    Is there any way so that i can share the snaps of my map and u could tell me the solution for it.

  5. #5
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Clipping

    Quote Originally Posted by dineshdreamworld View Post
    In method one what that "Sprite.TRANS_NONE" is for. Actually i came to know that it doesnt move anything here but why it is included in the syntax. What that sprite does in the syntax here. Pls explain me.
    It is there because you have to have some value for that parameter. For example, you could also have Sprite.TRANS_MIRROR, to draw the region flipped about its vertical axis. You can learn all about this in the Java Docs for the Graphics class.

    Quote Originally Posted by dineshdreamworld View Post
    Actually i m developing a game where there is a map in which i have to take every map parts differently and now i hav to join them but since i have arranged them in particular rectangular format i m not able to join them properly and so wat could b done for it.

    Is there any way so that i can share the snaps of my map and u could tell me the solution for it.
    You might do well to read the Java Docs for the class javax.microedition.lcdui.game.TiledLayer.

    Graham.

  6. #6
    Registered User
    Join Date
    Feb 2010
    Posts
    45

    Re: Clipping

    As u said Graham i have gone through the tile class but it will not help me since here when a particular king conquer the territory that part of the map should be colored with the king's flag color. So in order to do that the Tile class will not help me can u suggest me any other thing.
    Also i tried using clipping by arranging the part of images in one window but while joining those parts the rectangular frame comes and so i m not able to join the map parts properly.
    Is there any way so that i can just take the image boundary into consideration and draw only that part of the image i.e within the boundary part.

  7. #7
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Clipping

    Quote Originally Posted by dineshdreamworld View Post
    As u said Graham i have gone through the tile class but it will not help me since here when a particular king conquer the territory that part of the map should be colored with the king's flag color. So in order to do that the Tile class will not help me can u suggest me any other thing.
    Either:

    1. you use a TiledLayer, and change the map data, so that you change what is displayed, or

    2. you implement your own code similar to TiledLayer, but with the extra functionality you want.

    Quote Originally Posted by dineshdreamworld View Post
    Also i tried using clipping by arranging the part of images in one window but while joining those parts the rectangular frame comes and so i m not able to join the map parts properly.
    Is there any way so that i can just take the image boundary into consideration and draw only that part of the image i.e within the boundary part.
    I'm not sure I understand what you mean. Do you mean that you want to draw the map in a rectangle, and parts of it draw outside? This is easy to fix: it is what clipping is for.

    If you're using drawRegion(), then just use setClip() to set the window area first.

    If you're using drawImage(), then you'll need to use setClip() and clipRect() in combination. But you should be using drawRegion().

    Or do you mean something else?

    Graham.

  8. #8
    Registered User
    Join Date
    Feb 2010
    Posts
    45

    Re: Clipping

    Hello Graham My problem is solved. Actually i developed an image with the transparent background and then clipped it and after clipping i joined d parts.After that it solved my problems and i was able to join different parts of map very easily.

Similar Threads

  1. Image Clipping and Transparency
    By vikrambk in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2007-11-05, 10:35
  2. Off Screen Buffer Clipping Issue
    By foster18 in forum Mobile Java General
    Replies: 1
    Last Post: 2005-12-15, 04:16
  3. Problem of drawing FLIPPED Image after clipping in Nokia 3510i handset
    By radhesh in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2003-12-10, 03:29
  4. Clipping doesn't work with DirectGraphics?
    By jengstro in forum Mobile Java Media (Graphics & Sounds)
    Replies: 33
    Last Post: 2003-09-02, 10:58
  5. Possible clipping bug on 7650 v4.39
    By john_barker in forum Mobile Java General
    Replies: 1
    Last Post: 2003-03-14, 09:56

Posting Permissions

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