Solved

Easy Image one

Posted on 1998-11-18
3
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

626 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