Solved

Easy Image one

Posted on 1998-11-18
3
153 Views
Last Modified: 2010-03-30
I have an image that I want to display cropped in an animation.  The idea is to display more and more of the image through execution of a loop.
I know how to display it scaled, but I need it cropped.
Got any ideas?
0
Comment
Question by:robinM
3 Comments
 
LVL 7

Expert Comment

by:conick
ID: 1227667
You may want to look at the drawImage in the Graphics class if you want to crop
as a rectangle

drawImage(Image img, int dx1,  int dy1,  int dx2,  int dy2,  int sx1,  int sy1,  int sx2,  int sy2,
                                  ImageObserver observer)

the sx1,sy1 is the x and y coordinate of the image, the upper left corner
the sx2,sy2 is the x and y coordinate of the image, the lower right corner

there are other ways to crop... this is just a quick suggestion
0
 
LVL 5

Accepted Solution

by:
fontaine earned 20 total points
ID: 1227668
There is a CropImageFilter class part of the java.awt.image package.

Example of use:

import java.awt.image.*;
import java.awt.*;
//...

// original image:
Image image = ...

// we create a filter to crop the image in a box starting at (25, 30), that is 50 pixels
// wide and 50 pixels high

CropImageFilter filter = new CropImageFilter(25,30,50,50);

// we create the new image, cropped version of the original:

Toolkit toolkit = Toolkit.getDefaultToolkit();
Image croppedImage = toolkit.createImage(new FilteredImageSource(image.getSource(), filter));
0
 

Author Comment

by:robinM
ID: 1227669
Nice one fontaine. Exactly what I was looking for.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now