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;
}
}
}

DBImg: 图片文件-二进制文件的转换的更多相关文章

  1. C#实现图片文件到数据流再到图片文件的转换 --转

    /----引入必要的命名空间 using System.IO; using System.Drawing.Imaging; //----代码部分----// private byte[] photo; ...

  2. html5中将图片的绝对路径转换成文件对象

    html5中将图片的绝对路径转换成文件对象 将图片的绝对路径转换成base64编码,请看这篇文章 我们先来理解基本知识点: 1. 理解HTML5中的FileList对象与file对象. 在HTML5中 ...

  3. js 将图片文件转换成base64

      1.情景展示 在JavaScript中,如何使用图片文件转换成base64? 2.解决方案 /** * 网络图像文件转Base64 * @param img dom对象 */ function g ...

  4. js如何将选中图片文件转换成Base64字符串?

    如何将input type="file"选中的文件转换成Base64的字符串呢? 1.首先了解一下为什么要把图片文件转换成Base64的字符串 在常规的web开发过程中,大部分上传 ...

  5. winform利用itextsharp.dll实现图片文件转换PDF格式文件

    1.利用itextsharp.dll实现单个图片文件转换为PDF格式文件, 可以使用以下类: void ConvertJPG2PDF(string jpgfile, string pdf) { var ...

  6. C#实现图片文件到数据流再到图片文件的转换

    //----引入必要的命名空间using System.IO;using System.Drawing.Imaging; //----代码部分----// private byte[] photo;/ ...

  7. WPF中实现图片文件转换成Visual对象,Viewport3D对象转换成图片

    原文:WPF中实现图片文件转换成Visual对象,Viewport3D对象转换成图片 1.图片文件转换成Visual对象 private Visual CreateVisual(string imag ...

  8. C#实现图片文件到数据流,再到图片文件的转换

    //----引入必要的命名空间 using System.IO; using System.Drawing.Imaging; //----代码部分----// private byte[] photo ...

  9. C# 图片文件与字符串之间的转换

    1.将图片文件转化为字符串类型 2.将字符串类型的图片数据转换为本地图片保存

随机推荐

  1. ABAP-smartform-一页3列的条码打印

    1.自建barcode: se73->System bar code->change->create->new input the name of the bar code y ...

  2. arrow css

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. Objective-C(二、类和对象)

     类和对象 #import是include的升级版,可以自动防止重复包含,所以注意:大家以后在引入头文件的时候都使用import Foundation是一个框架,Foundation.h是Founda ...

  4. lucene索引文件格式

    转自:http://blog.csdn.net/whuqin 本文介绍下lucene生成的索引有哪些文件组成,每个文件包含了什么信息.基于Lucene 4.10.0. 数据结构 索引(index)包含 ...

  5. FZU 1911 Construct a Matrix

    题目链接:Construct a Matrix 题意:构造一个矩阵,要求矩阵的每行每列的和都不相同.矩阵的边长是前n项斐波那契的和. 思路:由sn = 2*(fn-1)+(fn-2)-1,只要知道第n ...

  6. 重点关注之Filter的使用(性能计数和错误处理)

    Web API中的filter与MVC中的filter非常类似,最主要的不同是,MVC中的filter放在命名空间System.Web.Mvc下,而Web API中的filter则放在命名空间Syst ...

  7. 在 Ubuntu 14.04/15.04 上配置 Node JS v4.0.0

    大家好,Node.JS 4.0 发布了,这个流行的服务器端 JS 平台合并了 Node.js 和 io.js 的代码,4.0 版就是这两个项目结合的产物——现在合并为一个代码库.这次最主要的变化是 N ...

  8. spring MVC 详细入门

    移步到这里:http://www.admin10000.com/document/6436.html

  9. js基础之动画(二)

    一.多物体同时运动 栗子一:多个Div,鼠标移入变高,动态下拉菜单 function startMove(obj,iTarget){  clearInterval(obj.timer); obj.ti ...

  10. linux下安装vtune_amplifier_xe_2015_update4

    说明:        linux系统: CentOS 6.0 Vtune版本: 2015 安装过程: 1.下载vtune_amplifier_xe_2015_update4.tar.gz(到官网去下载 ...