C#一些影像處理的函數

來源:互聯網
上載者:User

標籤:

 1         /// <summary> 2         /// 映像URL地址轉byte數組 3         /// </summary> 4         /// <param name="FileUrl">映像URL地址</param> 5         /// <returns>映像的byte數組</returns> 6         public static byte[] UrlToByte(string FileUrl) 7         { 8             return File.ReadAllBytes(FileUrl); 9         }10 11         /// <summary>12         /// 映像byte數組轉映像13         /// </summary>14         /// <param name="ByteOfImg">映像的byte數組</param>15         /// <returns>映像</returns>16         public static Image ByteToImage(byte[] ByteOfImg)17         {18             MemoryStream ms = new MemoryStream(ByteOfImg);19             Image image = Image.FromStream(ms);20             ms.Dispose();21             return image;22         }23 24         /// <summary>25         /// 映像轉byte數組26         /// </summary>27         /// <param name="img">映像</param>28         /// <returns>映像的byte數組</returns>29         public static byte[] ImageToByte(Image img)30         {31             MemoryStream mstream = new MemoryStream();32             img.Save(mstream, System.Drawing.Imaging.ImageFormat.Jpeg);33             byte[] byData = new Byte[mstream.Length];34             mstream.Position = 0;35             mstream.Read(byData, 0, byData.Length);36             mstream.Close();37             return byData;38         } 39 40 41         /// <summary>42         /// 映像轉灰階分量43         /// </summary>44         /// <param name="img">映像</param>45         /// <returns>映像的灰階分量</returns>46         public static byte[] ImageToY(Image img)47         {48             int Var_H = img.Height;49             int Var_W = img.Width;50             int tem_r, tem_g, tem_b = 0;51             int length = 0;52             Bitmap Var_SaveBmp = (Bitmap)img;53             byte[] gray = new byte[Var_H * Var_W];54 55             for (int j = 0; j < Var_H; j++)56                 for (int i = 0; i < Var_W; i++)57                 {58                     Color tem_color = Var_SaveBmp.GetPixel(i, j);59                     tem_r = tem_color.R;60                     tem_g = tem_color.G;61                     tem_b = tem_color.B;62                     gray[length++] = (byte)((tem_r * 38 + tem_g * 75 + tem_b * 15) >> 7);      //Gray = (R*38 + G*75 + B*15) >> 763                 }64             return gray;65         }

 

C#一些影像處理的函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.