1 /// <summary> 2 /// 生成缩略图返回byte[] 3 /// </summary> 4 /// <param name="fileName"></param> 5 /// <returns></returns> 6 private byte[] GetByteByPic(string fileName) 7 { 8 MemoryStream ms = new MemoryStream(); 9 10 Bitmap bitmap = new Bitmap(fileName); 11 12 //获取原图片的宽和高 13 int width = bitmap.Width; 14 int height = bitmap.Height; 15 Rectangle newPic = new Rectangle(0, 0, width, height); 16 17 //创建原图片的副本 18 System.Drawing.Image newImg = bitmap.Clone(newPic, 19 System.Drawing.Imaging.PixelFormat.DontCare); 20 System.Drawing.Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(CallBack); 21 22 //设置生成后的缩略图,其中200,200表示你需要得到的宽和高 23 System.Drawing.Image myThumbnail = bitmap.GetThumbnailImage(200, 200, CallBack, IntPtr.Zero); 24 25 //保存到内存里 26 myThumbnail.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); 27 28 myThumbnail.Dispose(); //释放图片资源 29 newImg.Dispose(); 30 bitmap.Dispose(); 31 32 return ms.ToArray(); //内在里解出来返回byte[] 33 } 34 35 private static bool CallBack() //这个委托方法需要是static的 36 { 37 return false; 38 } 39