Skip to main content

How to output the image segments in cache to a file!

2 replies [Last post]
hansenfan
Offline
Joined: 2010-09-18
Points: 0

Hi,

Now I Vector Object,it is contains many image segments,I want to output the image segments into a file.But it is fail!

BufferedImage bufImage = new BufferedImage(printWidth, printHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bufImage.createGraphics();
g.fillRect(0, 0, printWidth, printHeight);
int size = bufferImages.size();
for (int i = 0; i < size; i++) {
BufferedImage image = bufferImages.get(i);
g.drawImage(image, null, printWidth, printHeight);
}
g.dispose();
ImageIO.write(bufImage, FILE_POSTFIX, newFile);

Output file is null. so what happened?

Thanks in advance!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
hansenfan
Offline
Joined: 2010-09-18
Points: 0

Nobody knows?

hansenfan
Offline
Joined: 2010-09-18
Points: 0

Problem solved by myself.

int size = bufferImages.size();
int width = bufferImages.get(0).getWidth();
int height = 0;
// printHeight = height * size;
for (int i = 0; i < size; i++) {
height += bufferImages.get(i).getHeight();
}
BufferedImage bufImage = new BufferedImage(printWidth + 150, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bufImage.createGraphics();
g.fillRect(0, 0, printWidth + 150, height);
int y = 0;
for (int i = 0; i < size; i++) {
BufferedImage image = bufferImages.get(i);
g.drawImage(image, null, 0, y);
y += image.getHeight();
}
g.dispose();
ImageIO.write(bufImage, FILE_POSTFIX, newFile);