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


    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();

  • 相关阅读:
    Web测试与App测试的区别-总结篇
    Shell之基本用法
    Samba服务部署
    Linux基础(3)
    linux基础(2)
    linux基础(2)
    Linux基础(1)
    网络基础及网络协议
    操作系统简介
    计算机基础重要性
  • 原文地址:https://www.cnblogs.com/xuhaifeng/p/7344201.html
Copyright © 2020-2023  润新知