#region 返回图片的字节流byte[] ////// 返回图片的字节流byte[] /// /// /// /// public static byte[] getImageByte(string imagePath, WebClient webClient) { byte[] imgByte = null; try { //MessageBox.Show("getImageByte"); //Stopwatch stopwatch = new Stopwatch(); //stopwatch.Start(); //DateTime dateStart = DateTime.Now; if (PubFunc.UrlDiscern(imagePath)) { Bitmap bt = new Bitmap(webClient.OpenRead(imagePath)); imgByte = PubFunc.ImgToByte(bt); } else { using (FileStream files = new FileStream(imagePath, FileMode.Open)) { imgByte = new byte[files.Length]; files.Read(imgByte, 0, imgByte.Length); files.Close(); } } //stopwatch.Stop(); //MessageBox.Show((DateTime.Now - dateStart).TotalMilliseconds.ToString()); } catch (Exception ee) { MessageBox.Show(ee.ToString()); } return imgByte; } #endregion
登录后复制
#region 图片转换成字节流 ////// 图片转换成字节流 /// ///要转换的Image对象 /// 转换后返回的字节流 public static byte[] ImgToByte(Image img) { try { using (MemoryStream ms = new MemoryStream()) { byte[] imagedata = null; img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); imagedata = ms.GetBuffer(); return imagedata; } } catch (Exception ee) { MessageBox.Show(ee.ToString()); return null; } } #endregion
登录后复制
以上就是c# 返回图片的字节流byte[]的内容,更多相关内容请关注【创想鸟】(www.php.cn)!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2553397.html