trouble with icons

hi,i want to store an icon in a mysql database.i get the icon with fileSystemView.getSystemIcon(file).but i found nothing how to get the icon in a mysql database.i hope you can help.Andreas
[231 byte] By [andreas2007] at [2007-11-26 12:15:54]
# 1
Save the icon file in the host running the database and pass only filename to the database.
hellbinder at 2007-7-7 14:51:14 > top of Java-index,Archived Forums,Socket Programming...
# 2
how can i get the image from the icon?if i cast it to ImageIcon to get the image from the icon, i get a java.lang.ClassCastException: javax.swing.plaf.IconUIResourceor is there an other way to save it in a file?thank youAndreas
andreas2007 at 2007-7-7 14:51:14 > top of Java-index,Archived Forums,Socket Programming...
# 3

Getting Icon from file:

ImageIcon icon = new ImageIcon(filename);

buffered copying of file:

private void copyFile(File src, File dst) throws IOException {

InputStream in = new FileInputStream(src);

OutputStream out = new FileOutputStream(dst);

byte[] buf = new byte[1024];

int len;

while ((len = in.read(buf)) > 0){

out.write(buf, 0, len);

}

in.close();

out.close();

}

reading/writing of images from/to file is done by ImageIO class

hellbinder at 2007-7-7 14:51:14 > top of Java-index,Archived Forums,Socket Programming...
# 4

hi,

Sorry about my bad english.

I only want the displayed Icon for a file from the filesystem stored in an other file or in a database.

So i think, i need to convert the icon to an image and the imate to a bytestream or bytearray.

But i don't know how to get the image from the icon.

thank you

andreas

andreas2007 at 2007-7-7 14:51:14 > top of Java-index,Archived Forums,Socket Programming...
# 5

Something along these lines

Icon i = fileSystemView.getSystemIcon(f);

BufferedImage bi = new BufferedImage(i.getIconWidth(), i.getIconHeight(), BufferedImage.TYPE_INT_ARGB);

Graphics g = bi.getGraphics();

i.paintIcon(null, g, 0, 0);

g.dispose();

Then use ImageIO to convert the image to your chosen format.

itchyscratchy at 2007-7-7 14:51:14 > top of Java-index,Archived Forums,Socket Programming...
# 6
thanks a million, that helps.Andreas
andreas2007 at 2007-7-7 14:51:14 > top of Java-index,Archived Forums,Socket Programming...