.net - Display and saving images with WPF -
i decided port winform project wpf encounter problem: software has user space. normally, image selected via openfiledialog, image both stored , used control "image" (roundpb in code). but, winform code not work in wpf because properties not same picturebox "image". here current nonfunctional code :
private sub button_click(sender object, e routedeventargs) dim openfiledialog2 new microsoft.win32.openfiledialog() dim imagepath string = nothing if openfiledialog2.showdialog() = vbok imagepath = openfiledialog2.filename my.computer.filesystem.copyfile(imagepath, imagerep & system.environment.getenvironmentvariable("programfiles") & "\mts\profpic.png", overwrite:=true) else : exit sub : end if if roundpb isnot nothing roundpb.source.freeze() roundpb.source = new bitmapimage(new uri(imagepath, urikind.relative)) end sub private sub metrowindow_loaded(sender object, e routedeventargs) if my.computer.filesystem.fileexists(system.environment.getenvironmentvariable("programfiles") & "\mts\profpic.png") dim imagepath string = system.environment.getenvironmentvariable("programfiles") & "\mts\profpic.png" roundpb.source = new bitmapimage(new uri(imagepath, urikind.relative)) roundpb.source.freeze() end if end sub
absolutely nothing works, neither roundpb (which not showing picture) nor save, no error message returned. can enlighten me? thank you!
the expression
system.environment.getenvironmentvariable("programfiles") & "\mts\profpic.png"
should give absolute path, e.g. c:\program files\mts\profpic.png
, why try create relative uri?
do not set urikind
@ all:
roundpb.source = new bitmapimage(new uri(imagepath))
for saving file, expect result of line below?
imagerep & system.environment.getenvironmentvariable("programfiles") & "\mts\profpic.png",
you should remove imagerep
prefix.
Comments
Post a Comment