1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import java
.awt
.Image
;
31 import java
.awt
.image
.PixelGrabber
;
32 import java
.awt
.image
.ImageObserver
;
34 //import javax.imageio.ImageIO;
35 import java
.lang
.reflect
.Method
;
43 boolean m_bGrabbed
= false;
45 private ImageHelper(Image _aImage
)
49 // grab all (consume much memory)
54 m_aPixels
= new int[m_w
* m_h
];
55 PixelGrabber pg
= new PixelGrabber(m_aImage
, x
, y
, m_w
, m_h
, m_aPixels
, 0, m_w
);
60 catch (InterruptedException e
)
62 System
.err
.println("interrupted waiting for pixels!");
65 if ((pg
.getStatus() & ImageObserver
.ABORT
) != 0)
67 System
.err
.println("image fetch aborted or errored");
72 public int getWidth() {return m_aImage
.getWidth(null);}
73 public int getHeight() {return m_aImage
.getHeight(null);}
74 // direct access to a pixel
75 public int getPixel(final int x
, final int y
)
77 return m_aPixels
[y
* m_w
+ x
];
80 // Write down the current image to a file.
81 // public void storeImage(String _sFilename)
85 public static ImageHelper
createImageHelper(String _sFilename
)
86 throws java
.io
.IOException
89 File aFile
= new File(_sFilename
);
92 Class imageIOClass
= Class
.forName("javax.imageio.ImageIO");
93 Method readMethod
= imageIOClass
.getDeclaredMethod("read", new Class
[]{java
.io
.File
.class});
94 Object retValue
= readMethod
.invoke(imageIOClass
, new Object
[]{aFile
});
95 aImage
= (Image
)retValue
;
97 catch(java
.lang
.ClassNotFoundException e
) {
100 catch(java
.lang
.NoSuchMethodException e
) {
103 catch(java
.lang
.IllegalAccessException e
) {
106 catch(java
.lang
.reflect
.InvocationTargetException e
) {
112 String javaVersion
= System
.getProperty("java.version");
113 throw new java
.io
.IOException(
114 "Cannot construct object with current Java version " +
115 javaVersion
+ ": " + ex
.getMessage());
117 // aImage = ImageIO.read(aFile);
118 return new ImageHelper(aImage
);