123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
-
- namespace Common.system
- {
- /// <summary>
- /// 图片帮助类
- /// 创建人:赵耀
- /// 创建时间:2018年11月1日
- /// </summary>
- public class ImageHelper
- {
- /// <summary>
- /// 通过FileStream 来打开文件,这样就可以实现不锁定Image文件,到时可以让多用户同时访问Image文件
- /// </summary>
- /// <param name="path">图片位置</param>
- /// <returns></returns>
- public static Bitmap ReadBitmapFile(string path)
- {
- try
- {
- if (File.Exists(path))
- {
- FileStream fs = File.OpenRead(path); //OpenRead
- int filelength = 0;
- filelength = (int)fs.Length; //获得文件长度
- Byte[] image = new Byte[filelength]; //建立一个字节数组
- fs.Read(image, 0, filelength); //按字节流读取
- System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
- fs.Close();
- Bitmap bit = new Bitmap(result);
- return bit;
- }
- else
- return null;
- }
- catch (Exception)
- {
- return null;
- }
- }
- /// <summary>
- /// 通过FileStream 来打开文件,这样就可以实现不锁定Image文件,到时可以让多用户同时访问Image文件
- /// </summary>
- /// <param name="path">图片位置</param>
- /// <returns></returns>
- public static Image ReadImageFile(string path)
- {
- try
- {
- if (File.Exists(path))
- {
- FileStream fs = File.OpenRead(path); //OpenRead
- int filelength = 0;
- filelength = (int)fs.Length; //获得文件长度
- Byte[] image = new Byte[filelength]; //建立一个字节数组
- fs.Read(image, 0, filelength); //按字节流读取
- System.Drawing.Image result = System.Drawing.Image.FromStream(fs);
- fs.Close();
- return result;
- }
- else
- return null;
- }
- catch (Exception)
- {
- return null;
- }
- }
- }
- }
|