S
SveinErik
Hi, I'm trying to find a method to save bmp, jpg and png files as ico
files, 16x16 size. I have managed to convert and save bmp files to
icon, but only in 32x32 size. I can't figure out how to save it in the
size: 16x16, and I hope someone could help me out a bit?
Code that saves from bmp to ico (32x32):
private void cmdConvert_Click(object sender, EventArgs e)
{
string source = @"d:\image.bmp";
string target = @"d:\image.ico";
BmpToIcon(source, target);
}
public static void BmpToIcon(string sourcePath, string
targetPath)
{
// Retrieve the bitmap from the file.
Bitmap bmp = (Bitmap)Image.FromFile(sourcePath);
// Convert the bitmap to an icon.
Icon ico = Icon.FromHandle(bmp.GetHicon());
// Create a file stream to save the icon stream.
Stream st = new FileStream(targetPath, FileMode.Create);
// Create a stream writer to physical write the data to
the disk.
BinaryWriter wr = new BinaryWriter(st);
// Write the binary icon data to the file stream.
ico.Save(st);
// Close the file to write the stream to the disk.
wr.Close();
}
files, 16x16 size. I have managed to convert and save bmp files to
icon, but only in 32x32 size. I can't figure out how to save it in the
size: 16x16, and I hope someone could help me out a bit?
Code that saves from bmp to ico (32x32):
private void cmdConvert_Click(object sender, EventArgs e)
{
string source = @"d:\image.bmp";
string target = @"d:\image.ico";
BmpToIcon(source, target);
}
public static void BmpToIcon(string sourcePath, string
targetPath)
{
// Retrieve the bitmap from the file.
Bitmap bmp = (Bitmap)Image.FromFile(sourcePath);
// Convert the bitmap to an icon.
Icon ico = Icon.FromHandle(bmp.GetHicon());
// Create a file stream to save the icon stream.
Stream st = new FileStream(targetPath, FileMode.Create);
// Create a stream writer to physical write the data to
the disk.
BinaryWriter wr = new BinaryWriter(st);
// Write the binary icon data to the file stream.
ico.Save(st);
// Close the file to write the stream to the disk.
wr.Close();
}