Solved

Easy Image one

Posted on 1998-11-18
3
156 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse compiler vs Installed JREs option 3 77
mockito example issue 8 64
Arrays.asList  VS  ArrayList 4 45
javap not working 8 39
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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:

863 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

20 Experts available now in Live!

Get 1:1 Help Now