您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

C# 返回图片的字节流byte[]

2025/4/6 5:13:37发布48次查看
#region 返回图片的字节流byte[] /// <summary> /// 返回图片的字节流byte[] /// </summary> ///<param name="imagepath"> ///<param name="webclient"> /// <returns></returns> 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 图片转换成字节流 /// <summary> /// 图片转换成字节流 /// </summary> ///<param name="img">要转换的image对象 /// <returns>转换后返回的字节流</returns> 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[]的内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product