Convert From Icon to Image [Solved]
-
Hello, i am in a WPF project, but i need question about C#. I am using
System.Drawing.Icon.ExtractAssociatedIcon()
to getSystem.Drawing.Icon
. And i want to convert toSystem.Controls.Image
Can anyone help? Thank you in advamce.modified on Sunday, September 26, 2010 10:51 AM
-
Hello, i am in a WPF project, but i need question about C#. I am using
System.Drawing.Icon.ExtractAssociatedIcon()
to getSystem.Drawing.Icon
. And i want to convert toSystem.Controls.Image
Can anyone help? Thank you in advamce.modified on Sunday, September 26, 2010 10:51 AM
Look at Icon.ToBitmap in MSDN
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
Look at Icon.ToBitmap in MSDN
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
It does not help, and i have tried that Cannot implicitly convert type 'System.Drawing.Bitmap' to 'System.Windows.Controls.Image'
-
It does not help, and i have tried that Cannot implicitly convert type 'System.Drawing.Bitmap' to 'System.Windows.Controls.Image'
You are going to have to ask that one in the WPF forum!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
You are going to have to ask that one in the WPF forum!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
I Thing i got a hand of it. I was pretty sure it was a type. But it is a control. I got confused with normal Image class. it was the folowing code for solution
using ImageIcon = System.Drawing.Icon;
Extract Icon from exe and then converts
ImageIcon ico = ImageIcon.ExtractAssociatedIcon(dpi.LongFileName);
Bitmap bmp = ico.ToBitmap();
MemoryStream stream = new MemoryStream();
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
BitmapImage bmpImage = new BitmapImage();
bmpImage.BeginInit();
stream.Seek(0, SeekOrigin.Begin);
bmpImage.StreamSource = stream;
bmpImage.EndInit();dpi.FileIcon = new System.Windows.Controls.Image();
dpi.FileIcon.Source = bmpImage; -
I Thing i got a hand of it. I was pretty sure it was a type. But it is a control. I got confused with normal Image class. it was the folowing code for solution
using ImageIcon = System.Drawing.Icon;
Extract Icon from exe and then converts
ImageIcon ico = ImageIcon.ExtractAssociatedIcon(dpi.LongFileName);
Bitmap bmp = ico.ToBitmap();
MemoryStream stream = new MemoryStream();
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
BitmapImage bmpImage = new BitmapImage();
bmpImage.BeginInit();
stream.Seek(0, SeekOrigin.Begin);
bmpImage.StreamSource = stream;
bmpImage.EndInit();dpi.FileIcon = new System.Windows.Controls.Image();
dpi.FileIcon.Source = bmpImage; -
const string fileName = @"D:\MISC\ICONS\clock.ico";
Icon icon = new Icon(fileName);
Image iconImg = Image.FromHbitmap(icon.ToBitmap().GetHbitmap());Sorry - it doesn't work for him. His is WPF System.Windows.Controls.Image, not a System.Windows.Drawing.Image.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
I Thing i got a hand of it. I was pretty sure it was a type. But it is a control. I got confused with normal Image class. it was the folowing code for solution
using ImageIcon = System.Drawing.Icon;
Extract Icon from exe and then converts
ImageIcon ico = ImageIcon.ExtractAssociatedIcon(dpi.LongFileName);
Bitmap bmp = ico.ToBitmap();
MemoryStream stream = new MemoryStream();
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
BitmapImage bmpImage = new BitmapImage();
bmpImage.BeginInit();
stream.Seek(0, SeekOrigin.Begin);
bmpImage.StreamSource = stream;
bmpImage.EndInit();dpi.FileIcon = new System.Windows.Controls.Image();
dpi.FileIcon.Source = bmpImage;Wow! That's a lot of work! The last time I made an icon (or converted it back to something else) I just changed the extension from .bmp to .ico (or back again). Why does each new release make everything harder? ;)
Will Rogers never met me.
-
Wow! That's a lot of work! The last time I made an icon (or converted it back to something else) I just changed the extension from .bmp to .ico (or back again). Why does each new release make everything harder? ;)
Will Rogers never met me.
Actualy i am using WPF (Windows Presentation Framework). And Code Beehind is C#. I am used of windows form programing, so i assumed that Image class is same as windows Form, but it was actualy a control. Since i wanted to show in datagrid I shoud it store as BitmapImage not image class, and then use xaml to use that BitmapImage. So this conversion is totaly useless for me (Again, I thought it isn't a control), however it may help someone.