码迷,mamicode.com
首页 > 其他好文 > 详细

图片转换为缩略图(Byte->Byte)

时间:2017-08-11 11:00:31      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:rom   stream   height   绘制   bitmap   raw   保存   idt   pix   

float _thumbnail_X = 0;
float _thumbnail_Y = 0;
int _thumbnail_Width = 480;
int _thumbnail_Height = 480;
//新建内存变量存储原图数据
MemoryStream _sourceImage_MemoryStream = new MemoryStream();
_sourceImage_MemoryStream.Write(sourceByteImage, 0, sourceByteImage.Length);
//绘制原图片
Image _sourceImage = Image.FromStream(_sourceImage_MemoryStream);
//创建缩略图
Image _thumbnail = new Bitmap(_thumbnail_Width, _thumbnail_Height);
//开始绘制缩略图
Graphics _g = Graphics.FromImage(_thumbnail);
RectangleF _sourceRect = new RectangleF(sourceX, sourceY, sourceWidth, sourceHeight);
RectangleF _thumbnailRect = new RectangleF(_thumbnail_X, _thumbnail_Y, _thumbnail_Width, _thumbnail_Height);
_g.DrawImage(_sourceImage, _thumbnailRect, _sourceRect, GraphicsUnit.Pixel);
_g.Save();
//新建内存变量保存缩略图数据
MemoryStream _thumbnail_MemoryStream = new MemoryStream();
_thumbnail.Save(_thumbnail_MemoryStream, ImageFormat.Jpeg);
//新建数据组保存图片数据
byte[] _thumbnailByte = new byte[_thumbnail_MemoryStream.Length];
_thumbnail_MemoryStream.Position = 0;
_thumbnail_MemoryStream.Read(_thumbnailByte, 0, Convert.ToInt32(_thumbnail_MemoryStream.Length));
//关闭、释放资源

_sourceImage_MemoryStream.Dispose();

_sourceImage.Dispose();

_thumbnail.Dispose();

_thumbnail_MemoryStream.Dispose();

_sourceImage_MemoryStream.Close();

_thumbnail_MemoryStream.Close();

图片转换为缩略图(Byte->Byte)

标签:rom   stream   height   绘制   bitmap   raw   保存   idt   pix   

原文地址:http://www.cnblogs.com/xuhaifeng/p/7344201.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!