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 public 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
);
49 } catch (InterruptedException e
) {
50 System
.err
.println("interrupted waiting for pixels!");
53 if ((pg
.getStatus() & ImageObserver
.ABORT
) != 0) {
54 System
.err
.println("image fetch aborted or errored");
59 public int getWidth() {return m_aImage
.getWidth(null);}
60 public int getHeight() {return m_aImage
.getHeight(null);}
61 // direct access to a pixel
62 public int getPixel(int x
, int y
)
64 return m_aPixels
[y
* m_w
+ x
];
67 // Write down the current image to a file.
68 // public void storeImage(String _sFilename)
72 public static ImageHelper
createImageHelper(String _sFilename
)
73 throws java
.io
.IOException
76 File aFile
= new File(_sFilename
);
79 Class
<?
> imageIOClass
= Class
.forName("javax.imageio.ImageIO");
80 Method readMethod
= imageIOClass
.getDeclaredMethod("read", new Class
[]{java
.io
.File
.class});
81 Object retValue
= readMethod
.invoke(imageIOClass
, new Object
[]{aFile
});
82 aImage
= (Image
)retValue
;
84 catch(java
.lang
.ClassNotFoundException e
) {
87 catch(java
.lang
.NoSuchMethodException e
) {
90 catch(java
.lang
.IllegalAccessException e
) {
93 catch(java
.lang
.reflect
.InvocationTargetException e
) {
99 String javaVersion
= System
.getProperty("java.version");
100 throw new java
.io
.IOException(
101 "Cannot construct object with current Java version " +
102 javaVersion
+ ": " + ex
.getMessage());
104 // aImage = ImageIO.read(aFile);
105 return new ImageHelper(aImage
);