Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / July 2008

Tip: Looking for answers? Try searching our database.

java.awt.image.RescaleOp.filter() causes VM crash:     EXCEPTION_ACCESS_VIOLATION

Thread view: 
Bob Wobbler - 28 Jun 2008 22:07 GMT
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
Knute Johnson - 29 Jun 2008 01:33 GMT
> 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
[quoted text clipped - 63 lines]
>
> Robert

I'm getting the same error on Windows and none on Fedora 9.

But that really isn't what you need.  RescaleOp doesn't do what you
expect it to do, it is to modify the colors of the image.  I know the
name fooled me too.  What you need is an AffineTransformOp.  Use a scale
instance of the AffineTransform to scale your image.

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.swing.*;

public class test5 extends JPanel {
    BufferedImage small;

    public test5() {
        try {
            BufferedImage big = ImageIO.read(new File("kittens.jpg"));
            AffineTransform at =
             AffineTransform.getScaleInstance(0.4,0.4);
            AffineTransformOp op =
             new AffineTransformOp(at,(RenderingHints)null);
            small = op.filter(big,null);
            setPreferredSize(new Dimension(
             small.getWidth(),small.getHeight()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void paintComponent(Graphics g) {
        g.drawImage(small,0,0,null);
    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame f = new JFrame();
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                test5 t5 = new test5();
                f.add(t5,BorderLayout.CENTER);
                f.pack();
                f.setVisible(true);
            }
        });
    }
}

Signature

Knute Johnson
email s/nospam/knute2008/

Bob Wobbler - 30 Jun 2008 00:33 GMT
Worked perfectly! Thanks a lot Knute!
Roedy Green - 30 Jun 2008 18:31 GMT
On Sat, 28 Jun 2008 14:07:58 -0700 (PDT), Bob Wobbler
<bob.wobbler@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>But once my code reaches the RescaleOp's filter Operation the virtual
>machine crashes.

Any way to crash the JVM without using JNI is of great interest to
Sun. Create the tiniest possible SSCCE and post the bug on the bug
parade.
See http://mindprod.com/jgloss/bugs.html
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Knute Johnson - 01 Jul 2008 06:33 GMT
> On Sat, 28 Jun 2008 14:07:58 -0700 (PDT), Bob Wobbler
> <bob.wobbler@gmail.com> wrote, quoted or indirectly quoted someone who
[quoted text clipped - 7 lines]
> parade.
> See http://mindprod.com/jgloss/bugs.html

It appears to be a new bug.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6721083

May not show up for a few days they said.

Signature

Knute Johnson
email s/nospam/knute2008/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.