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. Getting image from resource file

Getting image from resource file

Scheduled Pinned Locked Moved C#
visual-studiocomgraphicshelplearning
3 Posts 3 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.
  • L Offline
    L Offline
    liqnit
    wrote on last edited by
    #1

    Hi I am trying to get an image from a resource file into a picturebox. using the following code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Reflection; using System.Resources; namespace WindowsApplication16 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Assembly Massem; Image Mimage; Massem = this.GetType().Assembly; ResourceManager RM = new ResourceManager("WindowsApplication16.PH1", Massem); Mimage = (Image)RM.GetObject("MIS_1.png"); pictureBox1.Image = Mimage; } } } the form has 1 button & 1 picture box. Resource name is : PH1.resx - inside there is the image file . the problem : When the code finsh i get a NULL image. Please advise. i used the explanation on the following MSDN: http://msdn2.microsoft.com/En-US/library/aa984408(VS.71).aspx

    Have a nice Day

    M L 2 Replies Last reply
    0
    • L liqnit

      Hi I am trying to get an image from a resource file into a picturebox. using the following code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Reflection; using System.Resources; namespace WindowsApplication16 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Assembly Massem; Image Mimage; Massem = this.GetType().Assembly; ResourceManager RM = new ResourceManager("WindowsApplication16.PH1", Massem); Mimage = (Image)RM.GetObject("MIS_1.png"); pictureBox1.Image = Mimage; } } } the form has 1 button & 1 picture box. Resource name is : PH1.resx - inside there is the image file . the problem : When the code finsh i get a NULL image. Please advise. i used the explanation on the following MSDN: http://msdn2.microsoft.com/En-US/library/aa984408(VS.71).aspx

      Have a nice Day

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      Hi! You have to take care to use the correct name for the resource. Usually you have to prefix the object's filename with the namespace of your application (e.g. "WindowsApplication16.MIS_1.png" or whatever your namespace is).

      Regards, mav -- Black holes are the places where God divided by 0...

      1 Reply Last reply
      0
      • L liqnit

        Hi I am trying to get an image from a resource file into a picturebox. using the following code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Reflection; using System.Resources; namespace WindowsApplication16 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Assembly Massem; Image Mimage; Massem = this.GetType().Assembly; ResourceManager RM = new ResourceManager("WindowsApplication16.PH1", Massem); Mimage = (Image)RM.GetObject("MIS_1.png"); pictureBox1.Image = Mimage; } } } the form has 1 button & 1 picture box. Resource name is : PH1.resx - inside there is the image file . the problem : When the code finsh i get a NULL image. Please advise. i used the explanation on the following MSDN: http://msdn2.microsoft.com/En-US/library/aa984408(VS.71).aspx

        Have a nice Day

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, I cant remember all the details, so this is what I do: - add the image file to the project, set it to "embedded resource" (you probably did that already) - use Designer to add some control (say picturebox) that consumes an image, and set it up to use your image - now look at the code Designer has generated for you, and copy/paste what you need - throw away what you no longer need Works the first time every time. :)

        Luc Pattyn


        try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }


        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