• 二进制图片格式转换


    View Code
     1  public static bool IsAllowedExtension(byte[] imgArray, FileExtension[] fileEx)
     2         {
     3             MemoryStream ms = new MemoryStream(imgArray);
     4             System.IO.BinaryReader br = new System.IO.BinaryReader(ms);
     5             string fileclass = "";
     6             byte buffer;
     7             try
     8             {
     9                 buffer = br.ReadByte();
    10                 fileclass = buffer.ToString();
    11                 buffer = br.ReadByte();
    12                 fileclass += buffer.ToString();
    13             }
    14             catch
    15             {
    16             }
    17             br.Close();
    18             ms.Close();
    19             foreach (FileExtension fe in fileEx)
    20             {
    21                 if (Int32.Parse(fileclass) == (int)fe)
    22                     return true;
    23             }
    24             return false;
    25         }
    26         public  enum FileExtension
    27         {
    28             JPG = 255216,
    29             GIF = 7173,
    30             PNG = 13780,
    31             SWF = 6787,
    32             RAR = 8297,
    33             ZIP = 8075,
    34             _7Z = 55122,
    35             XLS = 208207,
    36             XLSX = 8075,
    37             bmp = 6677
    38         }
    39 
    40 调用
    41  //判断下是否为gif
    42                         if (IsAllowedExtension(buffer, new FileExtension[] { FileExtension.GIF,FileExtension.PNG,FileExtension.bmp }))
    43                         {
    44                             using (MemoryStream newstream = new MemoryStream())
    45                             {
    46                                 bitmap.Save(newstream, System.Drawing.Imaging.ImageFormat.Jpeg);
    47                                 //
    48                                 using (Bitmap newbitmap = new Bitmap(newstream, true))
    49                                 {
    50 }
    51 }
    52 }
  • 相关阅读:
    CF869E The Untended Antiquity 解题报告
    Walk 解题报告
    CF911F Tree Destruction 解题报告
    P4397 [JLOI2014]聪明的燕姿
    洛谷 P2329 [SCOI2005]栅栏 解题报告
    洛谷 P3747 [六省联考2017]相逢是问候 解题报告
    set-erase
    set-empty
    set-empty
    set-end
  • 原文地址:https://www.cnblogs.com/haiwang/p/2663600.html
Copyright © 2020-2023  润新知