資源簡介
該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個文件信息
- 上一篇:Winform下最簡單易懂的MVC
- 下一篇:超漂亮的C#登錄窗口動畫效果
評論
共有 條評論