/*
JSmooth: a VM wrapper toolkit for Windows
Copyright (C) 2003 Rodrigo Reyes <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
static public class IconEntry
{ short bWidth; short bHeight; short bColorCount; short bReserved; int wPlanes; int wBitCount; long dwBytesInRes; long dwImageOffset;
static public class IconHeader
{ public long Size; /* Size of this header in bytes DWORD 0*/ public long Width; /* Image width in pixels LONG 4*/ public long Height; /* Image height in pixels LONG 8*/ public int Planes; /* Number of color planes WORD 12 */ public int BitsPerPixel; /* Number of bits per pixel WORD 14 */
/* Fields added for Windows 3.x follow this line */ public long Compression; /* Compression methods used DWORD 16 */ public long SizeOfBitmap; /* Size of bitmap in bytes DWORD 20 */ public long HorzResolution; /* Horizontal resolution in pixels per meter LONG 24 */ public long VertResolution; /* Vertical resolution in pixels per meter LONG 28*/ public long ColorsUsed; /* Number of colors in the image DWORD 32 */ public long ColorsImportant; /* Minimum number of important colors DWORD 36 */
static public BufferedImage[] loadImages(File f) throws IOException
{
InputStream istream = new FileInputStream(f);
BufferedInputStream buffin = new BufferedInputStream(istream);
BinaryInputStream in = new BinaryInputStream(buffin);
try {
in.mark(32000);
IconDir dir = new IconDir(in);
// System.out.println("DIR = " + dir);
IconEntry[] entries = new IconEntry[dir.idCount];
BufferedImage[] images = new BufferedImage[dir.idCount];
for (int i=0; i<dir.idCount; i++)
{
entries[i] = new IconEntry(in);
// System.out.println("ENTRY " + i + " = " + entries[i]);
}
static public void main(String[]args) throws Exception
{
File f = new File(args[0]);
Image img = IcoCodec.loadImages(f)[0];
// System.out.println("img = " + img);
javax.swing.JFrame jf = new javax.swing.JFrame("Test");
javax.swing.JButton button = new javax.swing.JButton(new javax.swing.ImageIcon(img));
jf.getContentPane().add(button);
jf.pack();
jf.setVisible(true);
}
}
/*
JSmooth: a VM wrapper toolkit for Windows
Copyright (C) 2003 Rodrigo Reyes <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
class BinaryInputStream extends FilterInputStream
{ public BinaryInputStream(InputStream in)
{ super(in);
}