I'm really sorry if this is similar to another question, or the question has already been answered, but I cannot make this work.
Bitmap image = new Bitmap(iw, ih, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(image);
g.CopyFromScreen(ix+left, iy,0,0, new System.Drawing.Size(iw, ih), CopyPixelOperation.SourceCopy);
MemoryStream memoryStream = new MemoryStream();
image.Save(memoryStream, ImageFormat.Png);
byte[] bitmapBytes = memoryStream.GetBuffer();
string bitmapString = Convert.ToBase64String(bitmapBytes, Base64FormattingOptions.InsertLineBreaks);
try
{
System.Net.WebClient Client = new System.Net.WebClient();
Client.Headers.Add("Content-Type", "binary/octet-stream");
byte[] result = Client.UploadFile("http://localhost/image/index.php", "POST", bitmapString);
string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length);
} catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex + " BITMAPSTR: "+bitmapString);
}
I'm taking a screenshot and then I want to upload it to my server via a php file. Which is supposed to save the file, and that works if I specify an already saved file on my computer, but I cannot make it work with a bitmap.
if ($_FILES["file"]["error"] == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["file"]["tmp_name"];
$name = $_FILES["file"]["name"];
move_uploaded_file($tmp_name, "./$name");
}
How do I convert a bitmap so it works with WebClient UploadFile?
EDIT
Error thrown (translated, might not be the exact words):
System.Net.WebException: An exception occured during a WebClient-request. ---> System.ArgumentException: Invalid characters in path.