?? form1.cs
字號:
?using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace LSB_Algorithm
{
public partial class Form1 : Form
{
//用以保存最大可隱藏的信息大小
private long _maxInfoSize = 0;
public Form1()
{
InitializeComponent();
}
#region 以下為信息隱藏TabPage的事件處理
/// <summary>
/// 選擇作為載體的BMP圖像
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void browsepic_btn_Click(object sender, EventArgs e)
{
OpenFileDialog filedlg = new OpenFileDialog();
filedlg.Filter = "24位位圖 (*.bmp)|*.bmp";
if (filedlg.ShowDialog() == DialogResult.OK)
{
FileStream fs = new FileStream(filedlg.FileName, FileMode.Open, FileAccess.Read);
using (Bitmap bmp = new Bitmap(fs))
{
if (bmp.PixelFormat != PixelFormat.Format24bppRgb)
{
MessageBox.Show("選擇的圖片并不是24位位圖!", "LSB",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
_maxInfoSize = (fs.Length - 54) / 4 - 3;
picpath_tb.Text = filedlg.FileName;
// picsize_lbl.Text = string.Format("{0:N0} 字節(jié)", fs.Length);
// maxinfo_lbl.Text = string.Format("{0:N0} 字節(jié)", _maxInfoSize);
}
}
fs.Close();
}
}
/// <summary>
/// 選擇待隱藏的文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void browsehiding_tb_Click(object sender, EventArgs e)
{
OpenFileDialog filedlg = new OpenFileDialog();
filedlg.Filter = "所有文件 (*.*)|*.*";
if (filedlg.ShowDialog() == DialogResult.OK)
{
FileStream fs = new FileStream(filedlg.FileName, FileMode.Open, FileAccess.Read);
if (fs.Length > _maxInfoSize)
{
MessageBox.Show(string.Format("所選文件過大!\n最大可隱藏文件大小為:{0} 字節(jié)", _maxInfoSize), "LSB",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
hiding_tb.Text = filedlg.FileName;
// infosize_lbl.Text = string.Format("{0:N0} 字節(jié)", fs.Length);
}
fs.Close();
}
}
/// <summary>
/// 生成包含隱藏信息的圖像
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void generate_btn_Click(object sender, EventArgs e)
{
if (picpath_tb.Text == string.Empty)
{
MessageBox.Show("請選擇載體圖像!", "LSB",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (picpath_tb.Text == string.Empty)
{
MessageBox.Show("請選擇要隱藏的文件!", "LSB",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
//備份原始文件
string backupFile = string.Format(@"{0}\{1}_original.bmp", Path.GetDirectoryName(picpath_tb.Text), Path.GetFileNameWithoutExtension(picpath_tb.Text));
File.Copy(picpath_tb.Text, backupFile, true);
//生成圖像
LSBEncrypt lsb = new LSBEncrypt(picpath_tb.Text, hiding_tb.Text);
lsb.ExecuteEncrypt();
MessageBox.Show("已成功生成含有隱藏信息的圖像!", "LSB",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
#endregion
#region 以下為信息提取TabPage的事件處理
/// <summary>
/// 選擇需要解碼的BMP圖像
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void selectPic_btn_Click(object sender, EventArgs e)
{
OpenFileDialog filedlg = new OpenFileDialog();
filedlg.Filter = "24位位圖 (*.bmp)|*.bmp";
if (filedlg.ShowDialog() == DialogResult.OK)
{
FileStream fs = new FileStream(filedlg.FileName, FileMode.Open, FileAccess.Read);
using (Bitmap bmp = new Bitmap(fs))
{
if (bmp.PixelFormat != PixelFormat.Format24bppRgb)
{
MessageBox.Show("選擇的圖片并不是24位位圖!", "LSB",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
originalPic_tb.Text = filedlg.FileName;
//bmpSize_lbl.Text = string.Format("{0:N0} 字節(jié)", fs.Length);
}
}
fs.Close();
}
}
/// <summary>
/// 選擇隱藏信息要保存到的路徑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void selectSavePath_btn_Click(object sender, EventArgs e)
{
SaveFileDialog filedlg = new SaveFileDialog();
filedlg.Filter = "所有文件 (*.*)|*.*";
if (filedlg.ShowDialog() == DialogResult.OK)
{
savePath_tb.Text = filedlg.FileName;
}
}
/// <summary>
/// 提取隱藏信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void extract_btn_Click(object sender, EventArgs e)
{
if (originalPic_tb.Text == string.Empty)
{
MessageBox.Show("請選擇要提取隱藏信息的圖像!", "LSB",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (savePath_tb.Text == string.Empty)
{
MessageBox.Show("請選擇隱藏信息的保存路徑!", "LSB",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
LSBDecrypt decrypt = new LSBDecrypt(originalPic_tb.Text, savePath_tb.Text);
if (decrypt.ExecuteDecrypt())
{
MessageBox.Show("已成功提取隱藏信息!", "LSB",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("所選擇的圖像似乎不包含任何隱藏信息!", "LSB",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
#endregion
private void tabPage1_Click(object sender, EventArgs e)
{
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -