c# - Is ExifLib usable in a WPF / XAML app? -
i want extract exif info jpg images. exiflib seemed selection simplify chore, , installed via nuget.
i tried started using sample code here (commenting out messagebox code now):
using (exifreader reader = new exifreader(@"c:\temp\testimage.jpg")) { // extract tag info using exiftags enumeration datetime datepicturetaken; if (reader.gettagvalue<datetime>(exiftags.datetimedigitized, out datepicturetaken)) { // whatever required extracted info //system.windows.messagebox.show(this, string.format("the image taken on {0}", // datepicturetaken), "image information"); //, messageboxbuttons.ok); } }
but error:
the best overloaded method match 'exiflib.exifreader.exifreader(system.io.stream)' has invalid arguments
and
argument 1: cannot convert 'string' 'system.io.stream'
both on line:
using (exifreader reader = new exifreader(@"c:\temp\testimage.jpg"))
is fixable, or exiflib not usable wpf / xaml app?
if exiflib not viable solution wpf / xaml app, alternatives exist?
update:
with code, simon mckenzie's answer:
private void btnloadnewphotoset_click(object sender, routedeventargs e) { using (var store = isolatedstoragefile.getuserstoreforapplication()) using (var stream = store.openfile("testimage.jpg", filemode.open)) using (var reader = new exifreader(stream)) { // ... } }
i still error:
the type or namespace name 'isolatedstorage' not exist in namespace 'system.io' (are missing assembly reference?)
this windows store (c#) app created in visual studio 2013. project's properties shows targets windows 8.1, , configuration manager shows configuration == debug, platform = x64)
my project's displayed references are:
.net windows store apps bing.maps.xaml exiflib microsoft visual c++ runtime bundle windows 8.1
what missing?
update 2:
when in reference manager @ assemblies.framework, says, "all of framework assembles referenced..." assume mscorlib.dll supposed 1 of these (it doesn't list them)?
i searched hard drive "mscorlib.dll" , i've got 1000000 of them, different sizes , dates. 1 should seek add together reference? i've got 1 in c:\program files (x86)\reference assemblies\microsoft\framework.netframework\v4.5 dated 7/9/2012 file size of 2,564,528 1 in c:\program files (x86)\reference assemblies\microsoft\framework.netcore\v4.5.1 to...you name it.
thinking "c:\program files (x86)\reference assemblies\microsoft\framework.netcore\v4.5.1" seemed best bet, tried reference via browse button, when did, got scolded with:
in interests of total disclosure, in reference manager windows 8.1, says, "the windows 8.1. sdk referenced."
for windows 8.1.extensions, shows me:
microsoft visual c++ 2013 runtime bundle windows 12.0 (unchecked) microsoft visual c++ 2013 runtime bundle 11.0 (checked)
since seems cause of 1 of warnings, reversed checkedness (checked 2013, unchecked other).
i checked:
behaviors sdk (xaml) 12.0 sqlite windows runtime 3.8.6 (because using sqlite in project)
update 3:
i found this: "isolated storage not available windows store apps. instead, utilize application info classes in windows.storage namespaces included in windows runtime api store local info , files." here.
update 4:
i'm waiting simon's example, i'm thinking might this:
using windows.storage; using exiflib; . . . private async void btnopenimgfiles_click(object sender, routedeventargs e) { fileopenpicker openpicker = new fileopenpicker(); openpicker.viewmode = pickerviewmode.thumbnail; openpicker.suggestedstartlocation = pickerlocationid.pictureslibrary; openpicker.filetypefilter.add(".jpg"); openpicker.filetypefilter.add(".jpeg"); openpicker.filetypefilter.add(".png"); ireadonlylist<storagefile> files = await openpicker.pickmultiplefilesasync(); (int = 0; < files.count; i++) { using (var randomaccessstream = await files[i].openasync(fileaccessmode.read)) using (var stream = randomaccessstream.asstream()) using (var exfrdr = new exifreader(stream)) { // ...exfrdr } } }
the string constructor not available in windows phone/windows store apps because aren't allowed direct filesystem access. instead need pass in stream containing image. here's illustration using fileopenpicker
. note utilize of asstream(...)
convert irandomaccessstream
stream
utilize exifreader
.
using system; using system.io; using windows.storage; using windows.storage.pickers; // ... var picker = new fileopenpicker(); picker.filetypefilter.add(".jpg"); var file = await picker.picksinglefileasync(); using (var randomaccessstream = await file.openasync(fileaccessmode.read)) { using (var stream = randomaccessstream.asstream()) { using (var reader = new exifreader(stream)) { string model; if (reader.gettagvalue(exiftags.model, out model)) { var dialog = new messagedialog(model, "camera model"); dialog.showasync(); } } } }
c# .net wpf windows-store-apps exiflib
No comments:
Post a Comment