我不需要非常高质量的图像。我将使用套接字发送此图像,因此我需要此图像尽可能小我需要一种压缩图像的方法
private void button1_Click_1(object sender, EventArgs e)
{
OpenFileDialog Open_File = new OpenFileDialog();
if (Open_File.ShowDialog() == DialogResult.OK)
{
FileStream fileStream = new FileStream(Open_File.FileName, FileMode.Open, FileAccess.Read);
int length = (int)fileStream.Length;
byte[] buffer = new byte[length];
fileStream.Read(buffer, 0, length);
Image x = byteArrayToImage(buffer);//this image I want to compression
//.............................
}
}
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}