locked
Embedding resource files and executing them localy on another machine RRS feed

  • Question

  • Hell everyone,
        I seem to be having a bit of a problem... I've used resources as images before, it was relatively easy using the code below...
      

    Dim asm As Assembly = assembly.getexecutingassembly()

    Dim resourcename As String = "Grim.bmp"

    Dim str As Stream = asm.GetManifestResourceStream("Grim.bmp")

    Dim img As Image = Image.FromStream(str)

    PictureBox1.file = img

    The problem I'm having is that I want to be able to execute other resource files... such as .exe .wmp  for videos, audio, etcetera. Unfortuanately I'm having trouble figuring that out...

    Could you please show me how I could edit my code to include other types of files, media, etc?

    Thank You very much in advance!

    -John




    I've found that I can load embedded videos using this code...

    Dim data() As Byte = My.Resources.GrimWebsite

    Dim file As New System.IO.FileStream("GrimWebsite.wmv", IO.FileMode.Create)

    file.Write(data, 0, data.Length)

    file.Close()

    Dim p As New Process

    p.StartInfo.FileName = "GrimWebsite.wmv"

    p.Start()



    but that only works for videos, if I try to use it for a bitmap,  jpg, or exe file like so...

    Dim data() As Byte = My.Resources.Grim

    Dim file As New System.IO.FileStream("Grim.BMP", IO.FileMode.Create)

    file.Write(data, 0, data.Length)

    file.Close()

    Dim p As New Process

    p.StartInfo.FileName = "Grim.BMP"

    p.Start()



    I get an error that states

    Error 1 Value of type 'System.Drawing.Bitmap' cannot be converted to '1-dimensional array of Byte'. 


    I'm fairly new to this, and this is just a hobby... so I have limited resorces to help me, I imagine it is a simple fix, but this all seems so complex... again, thank you!


    johnplaird.com
    Thursday, January 1, 2009 3:42 PM

Answers

  • My.Resources.Grim is Bitmap type. You can directly use My.Resources.Grim.Save to save the image to disk in this scenario. Try it. If  you have any further issues, feel free to tell us. 
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by thisishaydes Friday, January 9, 2009 11:37 AM
    Wednesday, January 7, 2009 7:23 AM

All replies

  • According to your subject line, you're having trouble getting those resources onto another machine, but you seem to be asking how to include other types of files as resources in the body of your post.  I'll try to answer both, just in case.

    You can include any type of file as a resource at least two different ways.  One, by adding it to the project: right click the project in the Solution Explorer, choose Add, Existing Item..., browse to the file, and click Add.  Once you have added it, select the newly added item in the Solution Explorer.  In the Properties Window, Change the Build Action to Content or Resource.

    The second way is to double click the My Project folder in the Solution Explorer, switch to the Resources tab, and drag/drop files onto it.  I think files added this way will become Embedded Resources by default.

    As for deploying the files, you've solved that problem by solving the other - Content or Resources should will be copied to the Bin\Debug or Bin\Release folders.  If you don't want to create install packages, you can just copy these folders.  That will work if all of the prerequisites are already installed on the target machine.

    Cheers.


    Thanks,
    Corey Furman
    Code Slabs
    ______________________________________________________
    Please mark posts as answer or helpful when they are.
    ______________________________________________________
    Going to Tech*Ed 2009? Email me at corey dot furman at gmail dot com.
    Thursday, January 1, 2009 4:59 PM
  •  I see, yeah I had several problems there, thank you that helps! I am also have quite the time with this...

    Dim data() As Byte = My.Resources.Grim 'Here I have it registered as a byte... it wont take

    Dim file As New System.IO.FileStream("Grim.BMP", IO.FileMode.Create)

    file.Write(data, 0, data.Length) 'It conflicts here, saying it cannot be converted to '1-dimensional array of Byte

    file.Close()

    Dim p As New Process

    p.StartInfo.FileName = "Grim.BMP"

    p.Start()


    'I've tried changing it to string, to boleen, to an object what data type should I use, and how should I use it to reflect correctly in this equation... I'm doing something wrong... I just don't see it

    1 Dim data As object = My.Resources.Grim  'I changed this to object, but line 3 conflicts with this statement

    2 Dim file As New System.IO.FileStream("Grim.BMP", IO.FileMode.Create)

    3 file.Write(data, 0, data.Length) ' what should I change this to?

    file.Write(object, 0, object.Length) ?? 'Nothing seems to work haha

    file.Close()

    Dim p As New Process

    p.StartInfo.FileName = "Grim.BMP"

    p.Start()


    johnplaird.com
    Thursday, January 1, 2009 8:07 PM
  • My.Resources.Grim is Bitmap type. You can directly use My.Resources.Grim.Save to save the image to disk in this scenario. Try it. If  you have any further issues, feel free to tell us. 
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by thisishaydes Friday, January 9, 2009 11:37 AM
    Wednesday, January 7, 2009 7:23 AM