constructor - Retrieving filename used to create Bitmap object (C#) -
is there method/property can obtain filename used create bitmap object?
for instance if bitmap created somewhere in main code passed method
bitmap myimage = new bitmap("c:\\images\\myimage.bmp"); mymethod(myimage); how mymethod determine name of file used create myimage
public void mymethod(bitmap myimage) { string imagefilename = // put here? } just clear value of imagefilename in mymethod should "c:\\images\\myimage.bmp". avoid creating global variable.
thanks.
you can't original file name bitmap object.
since bitmap class sealed, can't derive it. create own wrapper class , hold bitmap member:
class mybitmap { bitmap thebitmap; public mybitmap (string image) { imagefilename = image; //remember later. thebitmap = new bitmap(image); } public string imagefilename {get; set;} } then pass mybitmap instance mymethod , can file name easily. if need access properties of contained bitmap have create accessor functions in mybitmap work you, since contained object.
Comments
Post a Comment