• 大小: 83KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-07
  • 语言: C#
  • 标签: C#  图像  数据流  JPEG  

资源简介

该C#项目实现以下功能:1、将jpg格式图像转换为数据流;2、将数据流恢复jpg格式图像并显示。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Drawing.Imaging;
using System.Data.SqlClient;
using System.IO;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender EventArgs e)
        {

        }

        //byte[] photo;//要存储的图片二进制
        private void button1_Click(object sender EventArgs e)
        {
            //打开图片
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                //在界面上显示要存入的图片
                picImg.Image = Image.FromFile(openFileDialog1.FileName);

            }
        }

        byte[] photo;//要存储的图片二进制
        private void button2_Click(object sender EventArgs e)
        {
            Image img = new Bitmap(openFileDialog1.FileName);
            //video.GrabImage(pictureBox1.Handle “d:\\b.jpg“);
            MemoryStream stream = new MemoryStream();
            img.Save(stream ImageFormat.Bmp);
            BinaryReader br = new BinaryReader(stream);
            photo = stream.ToArray();
            //StreamWriter sw = new StreamWriter(“d:\\result.txt“);
            FileStream fs = new FileStream(“E:\\result.txt“ FileMode.Create FileAccess.Write);
            fs.Write(photo 0 photo.Length);
            fs.Close();

            stream.Close();
        }

        private void openFileDialog1_FileOk(object sender CancelEventArgs e)
        {

        }
        
        private void button3_Click(object sender EventArgs e)
        {
         
            
            
            byte[] bytes = photo;
            FileStream fs= new FileStream(“E:\\b.jpg“ FileMode.Create FileAccess.Write);
            //fs.Write(bytes 0 bytes.Length);
            fs.Write(photo 0 photo.Length);
           // pictureBox1.Image = Image.FromFile(“E:\\b.jpg“);
            this.pictureBox1.ImageLocation = “E:\\b.jpg“;
            fs.Flush();
            fs.Close();
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      13312  2012-07-18 14:12  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe

     文件      26112  2012-07-18 14:12  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.pdb

     文件      14328  2012-07-18 14:12  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.vshost.exe

     文件      12800  2012-07-18 14:12  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.exe

     文件      26112  2012-07-18 14:12  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\bin\Release\WindowsFormsApplication1.pdb

     文件       2407  2012-07-18 14:12  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs

     文件       5238  2012-07-18 11:21  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs

     文件       6017  2012-07-18 11:21  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\Form1.resx

     文件       4608  2012-07-17 10:01  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件       1219  2012-07-18 14:12  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.FileListAbsolute.txt

     文件        886  2012-07-18 11:21  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.csproj.GenerateResource.Cache

     文件      13312  2012-07-18 14:12  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.exe

     文件        180  2012-07-18 11:21  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Form1.resources

     文件      26112  2012-07-18 14:12  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.pdb

     文件       2939  2012-07-17 15:57  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\obj\Debug\WindowsFormsApplication1.Properties.Resources.resources

     文件       1235  2012-07-18 11:32  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\obj\Release\WindowsFormsApplication1.csproj.FileListAbsolute.txt

     文件        886  2012-07-18 11:24  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\obj\Release\WindowsFormsApplication1.csproj.GenerateResource.Cache

     文件      12800  2012-07-18 14:12  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\obj\Release\WindowsFormsApplication1.exe

     文件        180  2012-07-18 11:24  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\obj\Release\WindowsFormsApplication1.Form1.resources

     文件      26112  2012-07-18 14:12  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\obj\Release\WindowsFormsApplication1.pdb

     文件       2939  2012-07-17 15:54  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\obj\Release\WindowsFormsApplication1.Properties.Resources.resources

     文件        505  2012-07-17 09:58  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs

     文件       1390  2012-07-17 09:58  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\Properties\AssemblyInfo.cs

     文件       3121  2012-07-17 10:01  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.Designer.cs

     文件       6197  2012-07-17 10:01  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Resources.resx

     文件       1109  2012-07-17 09:58  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.Designer.cs

     文件        249  2012-07-17 09:58  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\Properties\Settings.settings

     文件       2469  2012-07-17 10:01  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\Resources\test2.jpg

     文件       3759  2012-07-17 15:54  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1\WindowsFormsApplication1.csproj

     文件        962  2012-07-17 09:58  图像与数据流相互转换\WindowsFormsApplication1\WindowsFormsApplication1.sln

............此处省略19个文件信息

评论

共有 条评论