c# - Best way to send image data to a server using WebClient -
i'm using webclient try , send image i've got on winform application central server. i've never used webclient before , i'm pretty sure i'm doing wrong.
first of all, i'm storing , displaying image on form so:
_screencap = new screencapture(); _screencap.onupdatestatus += _screen_caponupdatestatus; capturedimage = imjobj; imagepreview.image = capturedimage;
i've set event manager update imagepreview image when ever take screenshot. displaying when ever status changes this:
private void _screen_caponupdatestatus(object sender, progresseventargs e) { imagepreview.image = e.capturedimage; }
with image i'm trying pass server so:
using (var wc = new webclient()) { wc.uploaddata("http://filelocation.com/uploadimage.html", "post", imagepreview.image); }
i know should convert image byte[] i've no idea how that. please point me in right direction of go doing properly?
you can convert byte[] this
public byte[] imagetobytearray(system.drawing.image imagein) { memorystream ms = new memorystream(); imagein.save(ms,system.drawing.imaging.imageformat.gif); return ms.toarray(); }
if have path image, can this
byte[] bytes = file.readallbytes("imagepath");
Comments
Post a Comment