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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How to Create icon Object from Stream ?

How to Create icon Object from Stream ?

Scheduled Pinned Locked Moved C#
tutorialquestionlearning
9 Posts 5 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.
  • H Offline
    H Offline
    hdv212
    wrote on last edited by
    #1

    hi i use vs2005 and i add "Applications.ico" to my Application resource. How to Create Icon object from resource as stream ?? i could create Image object from resource as stream. but could not create Icon object. how to create Icon object from resource as stream ?? thanks

    J E P 3 Replies Last reply
    0
    • H hdv212

      hi i use vs2005 and i add "Applications.ico" to my Application resource. How to Create Icon object from resource as stream ?? i could create Image object from resource as stream. but could not create Icon object. how to create Icon object from resource as stream ?? thanks

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Icon myIcon = new Icon(theStream);

      ;P

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      H 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        Icon myIcon = new Icon(theStream);

        ;P

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        H Offline
        H Offline
        hdv212
        wrote on last edited by
        #3

        hi thanks for reply, but i did this work (like image object) and an error occured in this subject (Icon _icon = new Icon(_stream)) please give me an example for working correctly. thanks...

        J 1 Reply Last reply
        0
        • H hdv212

          hi thanks for reply, but i did this work (like image object) and an error occured in this subject (Icon _icon = new Icon(_stream)) please give me an example for working correctly. thanks...

          J Offline
          J Offline
          Judah Gabriel Himango
          wrote on last edited by
          #4

          Is the stream from a real icon stream? Or from an image stream?

          Tech, life, family, faith: Give me a visit. I'm currently blogging about: God-as-Judge, God-as-Forgiver The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

          1 Reply Last reply
          0
          • H hdv212

            hi i use vs2005 and i add "Applications.ico" to my Application resource. How to Create Icon object from resource as stream ?? i could create Image object from resource as stream. but could not create Icon object. how to create Icon object from resource as stream ?? thanks

            E Offline
            E Offline
            Eric Dahlvang
            wrote on last edited by
            #5

            ResourceManager res = new ResourceManager("MyNamespace.Properties.Resources", this.GetType().Assembly);
            Icon myIcon = (System.Drawing.Icon)res.GetObject("MyIcon");

            --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

            H 1 Reply Last reply
            0
            • E Eric Dahlvang

              ResourceManager res = new ResourceManager("MyNamespace.Properties.Resources", this.GetType().Assembly);
              Icon myIcon = (System.Drawing.Icon)res.GetObject("MyIcon");

              --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

              H Offline
              H Offline
              hdv212
              wrote on last edited by
              #6

              hi thanks for reply but when i write this code and compile my app the following error shown me : System.Resources.ResourceManager res = new System.Resources.ResourceManager("AmlakButtons.Properties.Resources", this.GetType().Assembly); System.Drawing.Icon _icon = (System.Drawing.Icon)res.GetObject("PRINTERS11"); Error : Unable to cast object of type 'System.Drawing.Bitmap' to type 'System.Drawing.Icon'

              E 1 Reply Last reply
              0
              • H hdv212

                hi i use vs2005 and i add "Applications.ico" to my Application resource. How to Create Icon object from resource as stream ?? i could create Image object from resource as stream. but could not create Icon object. how to create Icon object from resource as stream ?? thanks

                P Offline
                P Offline
                panks_r
                wrote on last edited by
                #7

                Well this is my first reply in cp, so please correct me if i'm wrong:) This works in vs2k3 so i guess it'll work in 2k5 as well.U can create a Bitmap from the stream, which can then be converted into an icon object. Bitmap b = new Bitmap(System.IO.Stream); Icon tempIcon = Icon.FromHandle(bmpTemp.GetHicon());//Hicon returns a handle to an icon which we use to create a temp icon. obIcon = (Icon)tempIcon.Clone(); Win32API.DestroyIcon(tempIcon.Handle);//we have to create a temp icon and destroy it coz of some resource disposal probs.

                H 1 Reply Last reply
                0
                • H hdv212

                  hi thanks for reply but when i write this code and compile my app the following error shown me : System.Resources.ResourceManager res = new System.Resources.ResourceManager("AmlakButtons.Properties.Resources", this.GetType().Assembly); System.Drawing.Icon _icon = (System.Drawing.Icon)res.GetObject("PRINTERS11"); Error : Unable to cast object of type 'System.Drawing.Bitmap' to type 'System.Drawing.Icon'

                  E Offline
                  E Offline
                  Eric Dahlvang
                  wrote on last edited by
                  #8

                  I assumed that your resource was an Icon. Try this:

                  ResourceManager res = new ResourceManager("AmlakButtons.Properties.Resources", this.GetType().Assembly);

                  Bitmap myBitmap = (System.Drawing.Bitmap)res.GetObject("PRINTERS11");
                  Icon _icon = Icon.FromHandle(myBitmap.GetHicon());
                  myBitmap.Dispose();

                  --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

                  1 Reply Last reply
                  0
                  • P panks_r

                    Well this is my first reply in cp, so please correct me if i'm wrong:) This works in vs2k3 so i guess it'll work in 2k5 as well.U can create a Bitmap from the stream, which can then be converted into an icon object. Bitmap b = new Bitmap(System.IO.Stream); Icon tempIcon = Icon.FromHandle(bmpTemp.GetHicon());//Hicon returns a handle to an icon which we use to create a temp icon. obIcon = (Icon)tempIcon.Clone(); Win32API.DestroyIcon(tempIcon.Handle);//we have to create a temp icon and destroy it coz of some resource disposal probs.

                    H Offline
                    H Offline
                    hfrmobile
                    wrote on last edited by
                    #9

                    I need Icon.FromHandle() method in Compact Framework but the FromHandle() method is not supported by the CF 1.0! So I searched a while and found an article at OpenNETCF.org[^] which did it: The code worked fine with PPC2002 and WM2003 but not works under WM2005... There seems to be a problem with the palette colors... The icon can be displayed but with wrong colors or transparency is a problem. 1. The SDF uses CreateDIBSection() with a BITMAPINFOHEADER parameter but MSDN and function prototype says that it is a BITMAPINFO. 2. P/invoked BITMAPINFOHEADER is missing biClrUsed and biClrImportant 3. Correcting issues 1+2 does not solve the problem. Very strange: If the application was launched using the debugger it works (icon displayed correctly). If launched without debugging (from within VS) the colors are not correct (black instead of transparency) The debugger seems to initialize something wich causes this behaviour but of course the app should be able to display the icons correctly without a debugger ;-) Thx for some help!

                    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