zoukankan      html  css  js  c++  java
  • DBImg: 图片文件-二进制文件的转换

    using System;
    using System.IO;
    using System.Drawing;
    //using System.Collections.Generic;
    //using System.Linq;
    //using System.Text;
    //using System.Threading.Tasks;
    
    namespace DBImg
    {
        public class ImageFile
        {
            public byte[] GetPictureData(string filePath)
            {
                if (!File.Exists(filePath))
                    return null;
    
                byte[] byteData = null;
                using (FileStream fs = new FileStream(filePath, FileMode.Open,FileAccess.Read))
                {
                    byteData = new byte[fs.Length];
                    fs.Read(byteData, 0, byteData.Length);
                    fs.Close();
                }
                return byteData;
            }
    
            public Image ReturnPhoto(byte[] streamByte)
            {
                MemoryStream ms = new MemoryStream(streamByte);
                Image img = Image.FromStream(ms);
                
                return img;
            }
    
            public bool SavePhoto(byte[] streamByte, string outputFile)
            {
                if (File.Exists(outputFile))
                {
                    File.Delete(outputFile);
                }
    
                bool saveCmplete = false;
                using (FileStream fs = new FileStream(outputFile, FileMode.CreateNew))
                {
                    fs.Write(streamByte, 0, streamByte.Length);
                    fs.Close();
                    saveCmplete = true;
                }
    
                return saveCmplete;
            }
        }
    }
  • 相关阅读:
    模块的种类和导入方法
    小知识点补充
    9.17模拟赛2.0
    hdu2181 哈密顿绕行世界问题
    9.17模拟赛
    9.15模拟赛
    P1084 疫情控制
    9.14模拟赛
    【bzoj1232】[Usaco2008Nov]安慰奶牛cheer
    P3128 [USACO15DEC]最大流Max Flow
  • 原文地址:https://www.cnblogs.com/qixue/p/4527226.html
Copyright © 2011-2022 走看看