java.awt.image.RescaleOp.filter() causes VM crash: EXCEPTION_ACCESS_VIOLATION
- From: Bob Wobbler <bob.wobbler@xxxxxxxxx>
- Date: Sat, 28 Jun 2008 14:07:58 -0700 (PDT)
I'm trying to scale a BufferedImage to fit it into a JLabel. First I
calculate the correct scale factor, the create the operation and a new
BufferedImage to copy the scaled image to.
But once my code reaches the RescaleOp's filter Operation the virtual
machine crashes. I couldn't really find any posts on this problem,
still I hope someone here might have solved this problem before.
Btw the method BufferedImage.getScaledInstance works, the only problem
is that it's result is an Image, but I need a BufferedImage because I
have to do some further processing with the data, but can't read any
pixels from the Image object this operation returns. So an alternative
solution would be to convert the Image to a BufferedImage - only
problem is that I don't know how to do that either.
Here's the code:
// read image
BufferedImage originalImage = ImageIO.read(imageFile);
// calculate scale factors for width and heigth
float scaleWidthFactor = (float) PANEL_WIDTH / (float)
originalImage.getWidth();
float scaleHeightFactor = (float) PANEL_HEIGHT / (float)
originalImage.getHeight();
// choose correct scale factor to fit image into the label
float scaleFactor = (scaleWidthFactor < scaleHeightFactor) ?
scaleWidthFactor : scaleHeightFactor;
// create rescale operation
BufferedImageOp rescaleOp = new RescaleOp(scaleFactor, 0, null);
// create new buffered image with correct dimensions for scaling
operation
BufferedImage scaledImage =
rescaleOp.createCompatibleDestImage(originalImage,
originalImage.getColorModel());
// scale image - CAUSES VM TO CRASH
rescaleOp.filter(originalImage, scaledImage);
// .. some more code (working)
centerLabel.setIcon(new ImageIcon(scaledImage));
And here's the error message I get:
#
# An unexpected error has been detected by Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d15d65d,
pid=23884, tid=20788
#
# Java VM: Java HotSpot(TM) Client VM (1.6.0_03-b05 mixed mode)
# Problematic frame:
# C [awt.dll+0xad65d]
#
# An error report file with more information is saved as
hs_err_pid23884.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
Thanks for your time & any hints you can give.
Robert
.
- Follow-Ups:
- Prev by Date: teste
- Next by Date: Re: Weird window close behavior
- Previous by thread: teste
- Next by thread: Re: java.awt.image.RescaleOp.filter() causes VM crash: EXCEPTION_ACCESS_VIOLATION
- Index(es):
Relevant Pages
|