Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Convert From Icon to Image [Solved]

Convert From Icon to Image [Solved]

Scheduled Pinned Locked Moved C#
csharpquestionwpfgraphicshelp
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saksida Bojan
    wrote on last edited by
    #1

    Hello, i am in a WPF project, but i need question about C#. I am using System.Drawing.Icon.ExtractAssociatedIcon() to get System.Drawing.Icon. And i want to convert to System.Controls.Image Can anyone help? Thank you in advamce.

    modified on Sunday, September 26, 2010 10:51 AM

    OriginalGriffO 1 Reply Last reply
    0
    • S Saksida Bojan

      Hello, i am in a WPF project, but i need question about C#. I am using System.Drawing.Icon.ExtractAssociatedIcon() to get System.Drawing.Icon. And i want to convert to System.Controls.Image Can anyone help? Thank you in advamce.

      modified on Sunday, September 26, 2010 10:51 AM

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      S 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        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.

        S Offline
        S Offline
        Saksida Bojan
        wrote on last edited by
        #3

        It does not help, and i have tried that Cannot implicitly convert type 'System.Drawing.Bitmap' to 'System.Windows.Controls.Image'

        OriginalGriffO 1 Reply Last reply
        0
        • S Saksida Bojan

          It does not help, and i have tried that Cannot implicitly convert type 'System.Drawing.Bitmap' to 'System.Windows.Controls.Image'

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          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 have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          S 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            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.

            S Offline
            S Offline
            Saksida Bojan
            wrote on last edited by
            #5

            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;

            L R 2 Replies Last reply
            0
            • S Saksida Bojan

              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;

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              const string fileName = @"D:\MISC\ICONS\clock.ico";
              Icon icon = new Icon(fileName);
              Image iconImg = Image.FromHbitmap(icon.ToBitmap().GetHbitmap());

              OriginalGriffO 1 Reply Last reply
              0
              • L Lost User

                const string fileName = @"D:\MISC\ICONS\clock.ico";
                Icon icon = new Icon(fileName);
                Image iconImg = Image.FromHbitmap(icon.ToBitmap().GetHbitmap());

                OriginalGriffO Offline
                OriginalGriffO Offline
                OriginalGriff
                wrote on last edited by
                #7

                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 have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                1 Reply Last reply
                0
                • S Saksida Bojan

                  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;

                  R Offline
                  R Offline
                  Roger Wright
                  wrote on last edited by
                  #8

                  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.

                  S 1 Reply Last reply
                  0
                  • R Roger Wright

                    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.

                    S Offline
                    S Offline
                    Saksida Bojan
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups