【发布时间】:2018-08-27 20:05:16
【问题描述】:
有什么方法可以将 bmp/jpg/png 图像转换为 WSQ 而不会丢失 C# 中的质量?使用 Image 类我们可以转换 bmp/jpg 但指纹输出图像的质量很差。我们能否获得与转换后的图像一样好的质量水平?
【问题讨论】:
有什么方法可以将 bmp/jpg/png 图像转换为 WSQ 而不会丢失 C# 中的质量?使用 Image 类我们可以转换 bmp/jpg 但指纹输出图像的质量很差。我们能否获得与转换后的图像一样好的质量水平?
【问题讨论】:
请试试这个,它可能会帮助你解决你的问题。这个唯一的主要逻辑请参考它并添加你的项目。
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string fileName = "", fileExt = "", FullPath = "";
WSQEncoder ws = new WSQEncoder();
private void btnBrowse_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "JPEG files (*.jpg)|*.jpg|BMP files (*.bmp)|*.bmp|PNG files (*.png)|*.png";
dialog.Title = "Select a JPEG/PNG/BMP file";
dialog.Multiselect = false;
if (dialog.ShowDialog() == DialogResult.OK)
{
FullPath = dialog.FileName;
string[] ext = dialog.FileName.Split('.');
pictureBox1.Image = new Bitmap(dialog.FileName);
fileExt = ext[1].ToString();
fileName = System.IO.Path.GetFileName(dialog.FileName);
txtOutputLocation.Text = "D:\\" + fileName.Replace(fileExt, "wsq");
if (fileExt.ToUpper() == "PNG")
cbFileType.SelectedIndex = 2;
else if (fileExt.ToUpper() == "BMP")
cbFileType.SelectedIndex = 1;
else
cbFileType.SelectedIndex = 0;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnClear_Click(object sender, EventArgs e)
{
pictureBox1.Image = null;
txtOutputLocation.Text = string.Empty;
cbFileType.SelectedIndex = 0;
}
private void btnConvert_Click(object sender, EventArgs e)
{
try
{
if (cbFileType.SelectedIndex < 0)
{
MessageBox.Show("Select an Image", "Image Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (txtOutputLocation.Text == "" || FullPath == "")
{
MessageBox.Show("Select an Image", "Image Required", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "WSQ file(*.wsq)|*.wsq";
saveFileDialog1.Title = "Save a WSQ File";
saveFileDialog1.ShowDialog();
if (saveFileDialog1.FileName != "")
{
//wsq.IMGtoWSQ(cbFileType.SelectedItem.ToString(), FullPath, txtOutputLocation.Text);
string msg = ws.IMGtoWSQ(cbFileType.SelectedItem.ToString(), FullPath, saveFileDialog1.FileName.ToString());
MessageBox.Show("Response Status : " + msg, "Conversion Status", MessageBoxButtons.OK, MessageBoxIcon.Information);
if (msg == "YES")
btnClear_Click(sender, e);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
【讨论】:
WSQEncoder 是什么,它来自哪里?整个答案中只有两行是相关的,它们甚至没有引用标准的 .net 组件。