save vector output image as .gif
Hi All,
Given a program below that will shows a image that is displayed using
vectors, I want to save the image shown as a xxx.gif.
Help is appreciated.
bH
import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class applicPxlBytesShoImg
extends JFrame {
public static void main(String[] argv) {
applicPxlBytesShoImg myExample = new applicPxlBytesShoImg("Pixel
Bytes To Image");
}
public applicPxlBytesShoImg(String title) {
super(title);
setSize(300, 335);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
dispose();
System.exit(0);
}
});
setVisible(true);
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
String hR, hG, hB, width, height, hexColor;
int red, green, blue, dx, dy, w, h;
Vector vec1;
Vector vec2;
try {
FileInputStream fin = new FileInputStream("ColorPixlData.txt");
ObjectInputStream in = new ObjectInputStream(fin);
vec1 = (Vector) in.readObject();
vec2 = (Vector) in.readObject();
in.close();
width = (String) vec1.elementAt(0);
w = Integer.parseInt(width);
height = (String) vec1.elementAt(1);
h = Integer.parseInt(height);
int index = 0;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
hexColor = (String) vec2.elementAt(index);
hR = hexColor.substring(0, 2);
hG = hexColor.substring(2, 4);
hB = hexColor.substring(4, 6);
red = Integer.parseInt(hR, 16);
green = Integer.parseInt(hG, 16);
blue = Integer.parseInt(hB, 16);
Color clr = new Color(red, green, blue);
g.setColor(clr);
// screen reposition dx,dy
dx = 0;
dy = 40;
// used a drawLine with the from and to being the same
// only a pragmatic solution
g.drawLine(x + dx, y + dy, x + dx, y + dy);
++index;
}
}
}
catch (Exception e) {
System.out.println("error getting data");
}
}
}