c# - I use XLABS to pick images from a gallery. How to get the filepath of the image? -
using xlabs in xamarin forms project , try reach underlying data of image not sure how current code. have viewmodel , page use function , function works fine. can pick image , it. want path/filedata.
my viewmodel:
public imagesource imagesource { { return _imagesource; } set { setproperty (ref _imagesource, value); } } private byte[] imagedata; public byte[] imagedata { { return imagedata; } } private byte[] readstream(stream input) { byte[] buffer = new byte[16*1024]; using (memorystream ms = new memorystream()) { int read; while ((read = input.read(buffer, 0, buffer.length)) > 0) { ms.write(buffer, 0, read); } return ms.toarray(); } } public async task selectpicture() { setup (); imagesource = null; try { var mediafile = await _mediapicker.selectphotoasync(new cameramediastorageoptions { defaultcamera = cameradevice.front, maxpixeldimension = 400 }); videoinfo = mediafile.path; imagesource = imagesource.fromstream(() => mediafile.source); } catch (system.exception ex) { status = ex.message; } } private static double convertbytestomegabytes(long bytes) { double rtn_value = (bytes / 1024f) / 1024f; return rtn_value; }
my page use it:
myviewmodel photogallery = null; photogallery = new myviewmodel (); private async void btnpickpicture_clicked (object sender, eventargs e) { await photogallery.selectpicture (); imgpicked.source = photogallery.imagesource; //imgpicked image x:name xaml. }
mediafile has path property. refer in viewmodel
videoinfo = mediafile.path;
Comments
Post a Comment