Home Ask Login Register

Developers Planet

Your answer is one click away!

Chris February 2016

Get File Path of a System.Drawing.Bitmap

Is there a way to get the File Path of a System.Drawing.Bitmap Type?

Something like:

My.Resources.myImg.GetFilePath Or


Obviously my above example does not exist. I am just showing my intention.


Visual Vincent February 2016

I'm not so sure the resources has a path, I think they're embedded in the application and then read into the memory (I could be wrong however).

If you want them to have a path you'd have to save them to a file. This saves the image in the Local Application Data folder:

Dim MyImgPath As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "myImg.bmp")
My.Resources.myImg.Save(MyImgPath, Imaging.ImageFormat.Bmp)

If you want to save the image in the same folder as your application:

Dim MyImgPath As String = IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory(), "myImg.bmp")

Zanidd February 2016

You might want to create your own object:

Public Class MyBitmap 
Inherits Bitmap 

Private _FilePath As String 

Public Property FilePath as String 
Return _FilePath
End Get 

' etc... 

The you could set the path and get it later on from the property

J-DawG February 2016

Pretty sure this isn't possible as there's quite a few ways to init a System.Drawing.Bitmap (e.g: Stream, Uri, another image object) and this Bitmap is a very generic object.

Depending on the technology you're using, there may be a more specialized image type that's better to use. For example, if you're using WPF, check out BitmapImage which does store the file path as the property UriSource.

If you really need to work with System.Drawing.Bitmaps, I'd recommend creating a model that houses both the bitmap and the file path. Like this:

    public Bitmap MyImage {get; set; }
    public string FilePath {get; set; }

Post Status

Asked in February 2016
Viewed 2,382 times
Voted 8
Answered 3 times


Leave an answer

Quote of the day: live life