我想将位图从Windows窗体应用程序(C#)发布到ASP.NET页并将其保存到服务器。我尝试了base64,但无法成功解码。这是我来自Windows Forms Application(C#)的代码:
GC.Collect();
Rectangle bounds = Screen.GetBounds(Point.Empty);
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
System.IO.MemoryStream stream = new System.IO.MemoryStream();
// bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
// byte[] imageBytes = stream.ToArray();
ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg);
// Create an Encoder object based on the GUID
// for the Quality parameter category.
System.Drawing.Imaging.Encoder myEncoder =
System.Drawing.Imaging.Encoder.Quality;
// Create an EncoderParameters object.
// An EncoderParameters object has an array of EncoderParameter
// objects. In this case, there is only one
// EncoderParameter object in the array.
EncoderParameters myEncoderParameters = new EncoderParameters(1);
EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder,
20L);
myEncoderParameters.Param[0] = myEncoderParameter;
bitmap.Save(stream, jgpEncoder,
myEncoderParameters);
byte[] imageBytes = stream.ToArray();
string base64String = Convert.ToBase64String(imageBytes);
var helloWorldString = "SSKEY="+base64String;
var array = Encoding.ASCII.GetBytes(helloWorldString);
HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("http://localtest.yagosinc.com/SupportView/postScreen.aspx?key="+Environment.UserDomainName);
request.Method = "POST";
request.ContentLength = array.Length;
request.ContentType = "application/x-www-form-urlencoded";
var Url = "";
using (Stream postdata = request.GetRequestStream())
{
postdata.Write(array, 0, array.Length);
}