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;
            }
        }
    }
  • 相关阅读:
    Dockerfile构建镜像
    00基础复习
    docker的网络(基础)
    02-Mysql中的运算符
    01-mysql中的数据类型
    Docker客户端连接Docker Daemon的方式
    docker-ce快速部署
    ubuntu18.04 server配置静态ip
    html语义化小记录
    webpack导入es6的简单应用
  • 原文地址:https://www.cnblogs.com/qixue/p/4527226.html
Copyright © 2011-2022 走看看