Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将图像作为字节数组发送到REST服务_C#_Image_Rest_Image Processing_Byte - Fatal编程技术网

C# 将图像作为字节数组发送到REST服务

C# 将图像作为字节数组发送到REST服务,c#,image,rest,image-processing,byte,C#,Image,Rest,Image Processing,Byte,我正在开发一个REST服务,该服务将用于处理图像,例如,更改亮度或对比度。我目前有一个Windows窗体应用程序,在将图像发送给其他人之前,我会将图像上载到该应用程序 以下是我到目前为止在其余部分上接收字节的代码: IRestServiceImpl.cs [OperationContract] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBody

我正在开发一个REST服务,该服务将用于处理图像,例如,更改亮度或对比度。我目前有一个Windows窗体应用程序,在将图像发送给其他人之前,我会将图像上载到该应用程序

以下是我到目前为止在其余部分上接收字节的代码:

IRestServiceImpl.cs

[OperationContract]
[WebInvoke(Method = "POST",
    ResponseFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.Wrapped,
    UriTemplate = "json/{id}")]
string jsonData(byte[] id);
public string jsonData(byte[] id) {
    return "The byte array is" + id;
}
RestServiceImpl.svc.cs

[OperationContract]
[WebInvoke(Method = "POST",
    ResponseFormat = WebMessageFormat.Json,
    BodyStyle = WebMessageBodyStyle.Wrapped,
    UriTemplate = "json/{id}")]
string jsonData(byte[] id);
public string jsonData(byte[] id) {
    return "The byte array is" + id;
}
这是我试图从表单发送它的尝试,但它在VisualStudio的控制台中返回空白

private async void btnRestSend_Click(object sender, EventArgs e) {

        byte[] byteArray = ImageManipulation.ImgToByte(pictureBox1.Image);
        ByteArrayContent byteContent = new ByteArrayContent(byteArray);
        var url = "http://localhost:52278/RestServiceImpl.svc/json/";
        HttpClient client = new HttpClient();

        HttpResponseMessage response = await client.PostAsync(new Uri(url), byteContent);

        string responseBody = await response.Content.ReadAsStringAsync();

        Console.WriteLine(responseBody);
}
ImgToByte

public static byte[] ImgToByte(Image img) {
    //Converts an Image to a Byte
    ImageConverter converter = new ImageConverter();
    return (byte[])converter.ConvertTo(img, typeof(byte[]));
}
如何将字节数组成功发送到rest服务,以便在其中操作它


提前感谢:)

您可以将字节数组转换为base 64字符串,以便将其作为字符串或JSON对象内部发送到前端

string base64Image = Convert.ToBase64String(byteArray);    

*Convert属于系统库

您可以将字节数组转换为base 64字符串,以便将其作为字符串或JSON对象内部发送到前端

string base64Image = Convert.ToBase64String(byteArray);    
*转换属于系统库