假如使用流输出一个图片,在下面代码加上输出时候的宽和高
FileStream FsImg = new FileStream(Server.MapPath("xx.gif" ), FileMode.Open);
byte[] imgByte = new byte[FsImg.Length];
FsImg.Read(imgByte, 0, imgByte.Length);
FsImg.Close();
Response.Clear();
Response.OutputStream.Write(imgByte, 0, imgByte.Length);
Response.End();
[解决办法]
//将byte[]转换为Image
public Image ReadImage(byte[] bytes)
{
FileStream fs=new FileStream("imagetemp1",FileMode.Create,FileAccess.Write,FileShare.None);
foreach(byte a in bytes)
{
fs.WriteByte(a);
}
fs.Close();
fs=new FileStream("imagetemp1",FileMode.Open,FileAccess.Read,FileShare.None);
BinaryFormatter bf = new BinaryFormatter();
object obj=bf.Deserialize(fs);
fs.Close();
return (Image)obj;
}
private byte[] GetThumbnailImage(System.Drawing.Image img)
{
byte[] imgByte;
float iScale = img.Height > img.Width ? (float)img.Height / 100 :(float)img.Width / 100;
img = img.GetThumbnailImage((int)(img.Width/iScale),(int)(img.Height/iScale), null, IntPtr.Zero);
MemoryStream memStream = new MemoryStream();
img.Save(memStream, System.Drawing.Imaging.ImageFormat.Jpeg);
memStream.Flush();
imgByte = memStream.ToArray();
return imgByte;
}