package
com.FineReport.function;
import
java.awt.image.BufferedImage;
import
java.io.BufferedOutputStream;
import
java.io.File;
import
java.io.FileOutputStream;
import
java.io.IOException;
import
javax.imageio.ImageIO;
import
com.FineReport.data.core.db.BinaryObject;
import
com.FineReport.script.AbstractFunction;
import
com.sun.jna.Library;
import
com.sun.jna.Native;
public
class
BinaryImage
extends
AbstractFunction{
static
WltRS wltrs = (WltRS) Native.loadLibrary(
"E:\\bmp\\WltRS"
, WltRS.
class
);
static
int
index =
0
;
public
Object run(Object[] args) {
int
current = index;
BinaryObject bo = (BinaryObject)args[
0
];
getFile(bo.getBytes(),
"E:\\bmp\\"
, current +
".wlt"
);
File file =
new
File(
"E:\\bmp\\"
+ current +
".wlt"
);
wltrs.GetBmp(
"E:\\bmp\\"
+ current +
".wlt"
,
1
);
File imagefile =
new
File(
"E:\\bmp\\"
+ current +
".bmp"
);
BufferedImage buffer =
null
;
try
{
buffer = ImageIO.read(imagefile);
}
catch
(IOException e) {
e.printStackTrace();
}
index = (++index)%
300
;
return
buffer;
}
public
static
void
getFile(
byte
[] bfile, String filePath, String fileName) {
BufferedOutputStream bos =
null
;
FileOutputStream fos =
null
;
File file =
null
;
try
{
File dir =
new
File(filePath);
if
(!dir.exists() && dir.isDirectory()){
dir.mkdirs();
}
file =
new
File(filePath+
"\\"
+fileName);
fos =
new
FileOutputStream(file);
bos =
new
BufferedOutputStream(fos);
bos.write(bfile);
}
catch
(Exception e) {
e.printStackTrace();
}
finally
{
if
(bos !=
null
) {
try
{
bos.close();
}
catch
(IOException e1) {
e1.printStackTrace();
}
}
if
(fos !=
null
) {
try
{
fos.close();
}
catch
(IOException e1) {
e1.printStackTrace();
}
}
}
}
}
interface
WltRS
extends
Library{
void
GetBmp(String str,
int
i);
}