2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.awt
.Image
;
22 import java
.awt
.image
.PixelGrabber
;
23 import java
.awt
.image
.ImageObserver
;
25 //import javax.imageio.ImageIO;
26 import java
.lang
.reflect
.Method
;
34 boolean m_bGrabbed
= false;
36 private ImageHelper(Image _aImage
)
40 // grab all (consume much memory)
45 m_aPixels
= new int[m_w
* m_h
];
46 PixelGrabber pg
= new PixelGrabber(m_aImage
, x
, y
, m_w
, m_h
, m_aPixels
, 0, m_w
);
51 catch (InterruptedException e
)
53 System
.err
.println("interrupted waiting for pixels!");
56 if ((pg
.getStatus() & ImageObserver
.ABORT
) != 0)
58 System
.err
.println("image fetch aborted or errored");
63 public int getWidth() {return m_aImage
.getWidth(null);}
64 public int getHeight() {return m_aImage
.getHeight(null);}
65 // direct access to a pixel
66 public int getPixel(final int x
, final int y
)
68 return m_aPixels
[y
* m_w
+ x
];
71 // Write down the current image to a file.
72 // public void storeImage(String _sFilename)
76 public static ImageHelper
createImageHelper(String _sFilename
)
77 throws java
.io
.IOException
80 File aFile
= new File(_sFilename
);
83 Class
<?
> imageIOClass
= Class
.forName("javax.imageio.ImageIO");
84 Method readMethod
= imageIOClass
.getDeclaredMethod("read", new Class
[]{java
.io
.File
.class});
85 Object retValue
= readMethod
.invoke(imageIOClass
, new Object
[]{aFile
});
86 aImage
= (Image
)retValue
;
88 catch(java
.lang
.ClassNotFoundException e
) {
91 catch(java
.lang
.NoSuchMethodException e
) {
94 catch(java
.lang
.IllegalAccessException e
) {
97 catch(java
.lang
.reflect
.InvocationTargetException e
) {
103 String javaVersion
= System
.getProperty("java.version");
104 throw new java
.io
.IOException(
105 "Cannot construct object with current Java version " +
106 javaVersion
+ ": " + ex
.getMessage());
108 // aImage = ImageIO.read(aFile);
109 return new ImageHelper(aImage
);