基本信息
源码名称:批量处理图片打印分辨率(DPI)工具源码
源码大小:0.08M
文件格式:.rar
开发语言:C#
更新时间:2019-03-27
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace EditImageDPI
{
public partial class MainForm : Form
{
private List<string> _fileList = new List<string>();
private int _newDpiWidth = 0;
private int _newDpiHeight = 0;
private string _saveFold = string.Empty;
private static object lockObject = new object();
public MainForm()
{
InitializeComponent();
}
private void OpenOToolStripButton_Click(object sender, EventArgs e)
{
try
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
if (openFileDialog1.FileNames.Length > 0)
{
InitByOpen();
foreach (string fileName in openFileDialog1.FileNames)
{
_fileList.Add(fileName);
FileInfo file = new FileInfo(fileName);
ListViewItem item = new ListViewItem(file.FullName);
item.SubItems.Add(Convert.ToString((file.Length / 1024)) "KB");
item.SubItems.Add(file.Extension.Replace(".", ""));
listViewFile.Items.Add(item);
}
GC.Collect();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"错误");
}
}
private void InitByOpen()
{
_fileList.Clear();
listViewFile.Items.Clear();
progressBar1.Maximum = openFileDialog1.FileNames.Length;
progressBar1.Step = 1;
toolStripStatusLabelAll.Text = "All: " openFileDialog1.FileNames.Length.ToString();
}
private void SavetoolStripButton_Click(object sender, EventArgs e)
{
try
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
_saveFold = folderBrowserDialog1.SelectedPath;
_newDpiWidth = Convert.ToInt32(toolStripComboBoxDPI_Width.Text);
_newDpiHeight = Convert.ToInt32(toolStripComboBoxDPI_Height.Text);
foreach (string fileName in _fileList)
{
EditImageDPIDelegate APM = new EditImageDPIDelegate(EditImageDPI);
APM.BeginInvoke(fileName, APM_CallBack, APM);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误");
}
}
private void EditImageDPI(string fileName)
{
lock (lockObject)
{
using (Bitmap newImage = new Bitmap(Image.FromFile(fileName)))
{
newImage.SetResolution(_newDpiWidth, _newDpiHeight);
newImage.Save(_saveFold "\\" GetFileNameByFileFullName(fileName),
System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
private string GetFileNameByFileFullName(string fullName)
{
int tag1 = fullName.LastIndexOf("\\");
return fullName.Substring(tag1, fullName.Length - tag1);
}
private delegate void EditImageDPIDelegate(string fileName);
private void APM_CallBack(IAsyncResult ar)
{
EditImageDPIDelegate APM = (EditImageDPIDelegate)ar.AsyncState;
APM.EndInvoke(ar);
this.Invoke(new APM_UpdateUIDelegate(APM_UpdateUI));
}
private void APM_UpdateUI()
{
progressBar1.PerformStep();
toolStripStatusLabelNow.Text = "Now: " progressBar1.Value.ToString();
if (progressBar1.Value == progressBar1.Maximum)
{
MessageBox.Show("批量处理图片DPI成功!","批量处理");
}
}
private delegate void APM_UpdateUIDelegate();
}
}