You Are Here:

Community: Developer Discussion Boards

#1 Old how to cut some part of Image - 2006-07-31, 10:01

Join Date: Jul 2006
Posts: 33
mshouab
Offline
Registered User
I want to get some part of the image by cutting like i have a square on the screen and i want to cut that part of the image which i think it should be done through cliping but i dnt know how can i use it for that purpose its urgent if any one provide me some sample code its really benificial for me.

Regards,
Muhammad Shouab
Reply With Quote

#2 Old Re: how to cut some part of Image - 2006-07-31, 19:01

Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
peterblazejewicz
Offline
Super Contributor
hi Muhammad,

#1
use Image class:
Quote:
createImage
public static Image createImage(Image image,
int x,
int y,
int width,
int height,
int transform)

Creates an immutable image using pixel data from the specified region of a source image, transformed as specified.
The source image may be mutable or immutable. For immutable source images, transparency information, if any, is copied to the new image unchanged.

On some devices, pre-transformed images may render more quickly than images that are transformed on the fly using drawRegion. However, creating such images does consume additional heap space, so this technique should be applied only to images whose rendering speed is critical.

The transform function used must be one of the following, as defined in the Sprite class:
Sprite.TRANS_NONE - causes the specified image region to be copied unchanged
Sprite.TRANS_ROT90 - causes the specified image region to be rotated clockwise by 90 degrees.
Sprite.TRANS_ROT180 - causes the specified image region to be rotated clockwise by 180 degrees.
Sprite.TRANS_ROT270 - causes the specified image region to be rotated clockwise by 270 degrees.
Sprite.TRANS_MIRROR - causes the specified image region to be reflected about its vertical center.
Sprite.TRANS_MIRROR_ROT90 - causes the specified image region to be reflected about its vertical center and then rotated clockwise by 90 degrees.
Sprite.TRANS_MIRROR_ROT180 - causes the specified image region to be reflected about its vertical center and then rotated clockwise by 180 degrees.
Sprite.TRANS_MIRROR_ROT270 - causes the specified image region to be reflected about its vertical center and then rotated clockwise by 270 degrees.

The size of the returned image will be the size of the specified region with the transform applied. For example, if the region is 100 x 50 pixels and the transform is TRANS_ROT90, the returned image will be 50 x 100 pixels.

Note: If all of the following conditions are met, this method may simply return the source Image without creating a new one:

* the source image is immutable;
* the region represents the entire source image; and
* the transform is TRANS_NONE.

Parameters:
image - the source image to be copied from
x - the horizontal location of the region to be copied
y - the vertical location of the region to be copied
width - the width of the region to be copied
height - the height of the region to be copied
transform - the transform to be applied to the region
Returns:
the new, immutable image
Throws:
NullPointerException - if image is null
IllegalArgumentException - if the region to be copied exceeds the bounds of the source image
IllegalArgumentException - if either width or height is zero or less
IllegalArgumentException - if the transform is not valid
Since:
MIDP 2.0
that is simply create new image using original image with applied "crop" information (start x/y, width/height)

#2
use Graphics.drawRegion
Quote:
drawRegion

public void drawRegion(Image src,
int x_src,
int y_src,
int width,
int height,
int transform,
int x_dest,
int y_dest,
int anchor)

Copies a region of the specified source image to a location within the destination, possibly transforming (rotating and reflecting) the image data using the chosen transform function.

The destination, if it is an image, must not be the same image as the source image. If it is, an exception is thrown. This restriction is present in order to avoid ill-defined behaviors that might occur if overlapped, transformed copies were permitted.

The transform function used must be one of the following, as defined in the Sprite class:
Sprite.TRANS_NONE - causes the specified image region to be copied unchanged
Sprite.TRANS_ROT90 - causes the specified image region to be rotated clockwise by 90 degrees.
Sprite.TRANS_ROT180 - causes the specified image region to be rotated clockwise by 180 degrees.
Sprite.TRANS_ROT270 - causes the specified image region to be rotated clockwise by 270 degrees.
Sprite.TRANS_MIRROR - causes the specified image region to be reflected about its vertical center.
Sprite.TRANS_MIRROR_ROT90 - causes the specified image region to be reflected about its vertical center and then rotated clockwise by 90 degrees.
Sprite.TRANS_MIRROR_ROT180 - causes the specified image region to be reflected about its vertical center and then rotated clockwise by 180 degrees.
Sprite.TRANS_MIRROR_ROT270 - causes the specified image region to be reflected about its vertical center and then rotated clockwise by 270 degrees.

If the source region contains transparent pixels, the corresponding pixels in the destination region must be left untouched. If the source region contains partially transparent pixels, a compositing operation must be performed with the destination pixels, leaving all pixels of the destination region fully opaque.

The (x_src, y_src) coordinates are relative to the upper left corner of the source image. The x_src, y_src, width, and height parameters specify a rectangular region of the source image. It is illegal for this region to extend beyond the bounds of the source image. This requires that:


x_src >= 0
y_src >= 0
x_src + width <= source width
y_src + height <= source height

The (x_dest, y_dest) coordinates are relative to the coordinate system of this Graphics object. It is legal for the destination area to extend beyond the bounds of the Graphics object. Pixels outside of the bounds of the Graphics object will not be drawn.

The transform is applied to the image data from the region of the source image, and the result is rendered with its anchor point positioned at location (x_dest, y_dest) in the destination.

Parameters:
src - the source image to copy from
x_src - the x coordinate of the upper left corner of the region within the source image to copy
y_src - the y coordinate of the upper left corner of the region within the source image to copy
width - the width of the region to copy
height - the height of the region to copy
transform - the desired transformation for the selected region being copied
x_dest - the x coordinate of the anchor point in the destination drawing area
y_dest - the y coordinate of the anchor point in the destination drawing area
anchor - the anchor point for positioning the region within the destination image
Throws:
IllegalArgumentException - if src is the same image as the destination of this Graphics object
NullPointerException - if src is null
IllegalArgumentException - if transform is invalid
IllegalArgumentException - if anchor is invalid
IllegalArgumentException - if the region to be copied exceeds the bounds of the source image
Since:
MIDP 2.0
#3
use GameCanvas and LayerManager, add your original image as Sprite and then simply call "setViewWindow" to restrict area of your image that are actually drawn on screen,
Quote:
setViewWindow

public void setViewWindow(int x,
int y,
int width,
int height)

Sets the view window on the LayerManager.

The view window specifies the region that the LayerManager draws when its paint(javax.microedition.lcdui.Graphics, int, int) method is called. It allows the developer to control the size of the visible region, as well as the location of the view window relative to the LayerManager's coordinate system.

The view window stays in effect until it is modified by another call to this method. By default, the view window is located at (0,0) in the LayerManager's coordinate system and its width and height are both set to Integer.MAX_VALUE.

Parameters:
x - the horizontal location of the view window relative to the LayerManager's origin
y - the vertical location of the view window relative to the LayerManager's origin
width - the width of the view window
height - the height of the view window
Throws:
IllegalArgumentException - if the width or height is less than 0
I think simply creating new image using Image.createImage method will be the easiest one to start with,

regards,
Peter
Reply With Quote

#3 Old Post Re: how to cut some part of Image - 2006-08-04, 10:05

Join Date: Jul 2006
Posts: 33
mshouab
Offline
Registered User
this isuue has been resolved you can use the following function to resolve that issue.

Code:
public Image getImageRegion(Image source, int x, int y, int width, int height){
        System.out.println("x="+x);
        System.out.println("y="+y);
        Image results = Image.createImage(width, height);
        results.getGraphics().drawImage(source, -x, -y, Graphics.LEFT |  Graphics.TOP);
        return results;
    }
Hope it helps.

Regards,
Muhammad Shouab
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Showing Part of Image from ByteArray (No Native API) vishwas_dot_h Mobile Java Media (Graphics & Sounds) 5 2009-08-27 13:17
HELP: Mutable Image to Immutable Image? rj_cybersilver Mobile Java Media (Graphics & Sounds) 1 2005-03-26 10:58
I want to Display an image as part of installation johnward1978 General Symbian C++ 1 2004-10-19 05:02
Series 40 - draw only a part of the image ionutianasi Mobile Java Media (Graphics & Sounds) 11 2003-09-08 05:25
Series 40 - image resizeing and drawing black and white only a part of an image ionutianasi Mobile Java Media (Graphics & Sounds) 3 2003-07-21 11:36

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ