Solved

Easy Image one

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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:

823 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