Solved

Easy Image one

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
table example 4 32
Unhandled exception type Exception 18 43
How to configure empty element in XML Document parser? 15 36
Crystal Reports Licensing Questions 4 38
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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

808 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