DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=35683>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=35683

           Summary: ArrayIndexOutOfBoundsException  in
                    IndexImage.getIndexedImage()  method
           Product: Batik
           Version: 1.5
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Utilities
        AssignedTo: [email protected]
        ReportedBy: [EMAIL PROTECTED]


I tried  to  get Indexed image from a *.png  image and obtained the  following  
exception:

java.lang.ArrayIndexOutOfBoundsException: -7
        at org.apache.batik.ext.awt.image.rendered.IndexImage$Cube.splitChannel
(Unknown Source)
        at org.apache.batik.ext.awt.image.rendered.IndexImage$Cube.split
(Unknown Source)
        at org.apache.batik.ext.awt.image.rendered.IndexImage.getIndexedImage
(Unknown Source)
        at ImageUtilities.encodeImageTo8Bit(ImageUtilities.java:49)
        at ImageTest.test(ImageTest.java:28)
        at ImageTest.main(ImageTest.java:37)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
Exception in thread "main" 


First  of  all  I  created a BufferedImage  object  from Image object. I  did 
it as  follows:

public static BufferedImage BufferedFromImage(Image i) {
        if (i == null)
            throw new NullPointerException();
        Panel p = new Panel();
        if (i instanceof BufferedImage)
            return (BufferedImage) i;
        i = new ImageIcon(i).getImage();
        int type = (hasAlpha(i)) ? BufferedImage.TYPE_INT_ARGB : 
BufferedImage.TYPE_INT_RGB;
        BufferedImage buf = new BufferedImage(i.getWidth(p), i.getHeight(p), 
type);
        Graphics2D g = (Graphics2D)buf.getGraphics();
        g.drawImage(i, 0, 0, p);
        g.dispose();
        return buf;
    }

    private static boolean hasAlpha(Image i) {
        if (i == null)
            throw new NullPointerException();
        if (i instanceof BufferedImage)
            return ((BufferedImage) i).getColorModel().hasAlpha();
        PixelGrabber grab = new PixelGrabber(i, 0, 0, 1, 1, false);
        try {
            grab.grabPixels();
        } catch (InterruptedException ex) {
        }
        ColorModel cm = grab.getColorModel();
        return cm.hasAlpha();
    }


I  attached a picture which results in exception. Note , that I tried to 
process other images and all worked properly except this image.

I  investigated source and found that this  exception  is  thrown due to 
negative array index value.

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to