locked
don't load the image RRS feed

  • Question

  • Hi 
    with compact framework and VB.net I want to visualize a jpg in a picturebox, I have copied the images in the same directory of the executable, but when I say to load the picture this error it always appears me.

    Could not find a part of the path '\c:\windows\01.jpg'.


    Where am I wrong? 
    Thanks

    Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles_ Button1.Click
    PictureBox1.Image = New Bitmap("01.jpg")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles_ Button2.Click
    Me.PictureBox1.Image = New Bitmap("02.jpg")
    End Sub
    End Class
    Wednesday, July 1, 2009 10:17 PM

Answers

  • Hi,

    If the image is added to your solution exploer already:

    Select the image in you solution explorer( IDE) --> Properties --> Set Copy to Output Directory to Copy if newer   ( It avoids to copy the file everytime to application folder)

    Try this code(C#):
    public static string directoryPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString());
    
    this.pictureBox1.Image = New Bitmap(directoryPath + "\\01.jpg");
    Regards,
    Malleswar

    • Marked as answer by warrentang Monday, July 6, 2009 9:33 AM
    Thursday, July 2, 2009 11:30 AM

All replies

  • Hi Anallie0,
    please try this.


    this
    .pictureBox1.Image = new Bitmap(@"/windows/01.jpg");




    Hope this might be helpful.


    Thanks Mohsin S.
    • Proposed as answer by Mohsin S Thursday, July 2, 2009 3:59 AM
    Thursday, July 2, 2009 3:59 AM
  • Hi Anallie0,

    As Mohsin written path will help you but some mistaken in path so i am just correct you.


    this .pictureBox1.Image = new Bitmap(@"windows/01.jpg" );


    Hope this may be help
    Pavan Pareta | If you find my post is helpful for you then mark as a answer.
    • Proposed as answer by WmDev Thursday, July 2, 2009 4:42 AM
    Thursday, July 2, 2009 4:42 AM
  • sorry
    the error message is: Could not find a part of the path '\01.jpg'. 

    but your solution is in C# and not in VB.

    Thanks
    Thursday, July 2, 2009 11:12 AM
  • sorry
    the error message is: Could not find a part of the path '\01.jpg'. 

    but your solution is in C# and not in VB.

    Thanks
    Thursday, July 2, 2009 11:12 AM
  • Pls check this :



    Me
    .pictureBox1.Image = New Bitmap(@"windows/01.jpg")
    Thanks Mohsin S.
    Thursday, July 2, 2009 11:16 AM
  • Hi,

    If the image is added to your solution exploer already:

    Select the image in you solution explorer( IDE) --> Properties --> Set Copy to Output Directory to Copy if newer   ( It avoids to copy the file everytime to application folder)

    Try this code(C#):
    public static string directoryPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString());
    
    this.pictureBox1.Image = New Bitmap(directoryPath + "\\01.jpg");
    Regards,
    Malleswar

    • Marked as answer by warrentang Monday, July 6, 2009 9:33 AM
    Thursday, July 2, 2009 11:30 AM