📄 htmlexporter.cs
字号:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Windows.Forms;
using VirtualPhotoOrganizer.Photo;
using System.Web;
using TXML;
namespace VirtualPhotoOrganizer.Util
{
/// <summary>
/// handles exporting photos to an html web album
/// </summary>
internal class HTMLExporter
{
// events
public delegate void UpdateMax(int newMax, string message);
public event UpdateMax MaxUpdate;
public delegate void UpdateProgress(int progress);
public event UpdateProgress ProgressUpdate;
public delegate void Finish();
public event Finish ProcessDone;
// the list of photos we wish to export
private Photos Photos;
// do we also export the description?
private bool ExpDesc;
// the progress dialog
private Dialogs.ProgressDialog Pd;
// are we supposed to cancel?
private bool Cancel;
private string URL = "http://virtualphotoorg.sourceforge.net";
// language strings
private string LsCopy;
private string LsThumb;
private string LsHTML;
private string LsPrev;
private string LsNext;
private string LsThumbs;
private string LsVPO;
private string LsDesc;
private string LsOverwrite;
private string LsResize;
public HTMLExporter(Photos photos, bool exportDescription, string language) {
Photos = (Photos) photos.Clone();
ExpDesc = exportDescription;
Cancel = false;
LoadStrings(language);
// create a new instance of the progressDialog
Pd = new VirtualPhotoOrganizer.Dialogs.ProgressDialog(this);
}
private void LoadStrings(string language) {
// get the strings for the ProgressDialog
try {
TXmlReader reader = XmlHandler.OpenLangFile();
LsCopy = reader.GetString("Progress", "Copy", "Copying Photos...");
LsThumb = reader.GetString("Progress", "Thumb", "Creating Thumbnails...");
LsHTML = reader.GetString("Progress", "HTML", "Writing HTML files...");
LsOverwrite = reader.GetString("Progress", "HTMLOverwrite", "The above file already exists in the destination path, do wish to overwrite it?");
LsResize = reader.GetString("HTML", "Resize", "Resizing Photos...");
reader.Close();
}
catch {
LsCopy = "Copying Photos...";
LsThumb = "Creating Thumbnails...";
LsHTML = "Writing HTML files...";
LsOverwrite = "The above file already exists in the destination path, do wish to overwrite it?";
LsResize = "Resizing Photos...";
}
// get the strings for the HTML files
try {
// load strings from file
TXmlReader reader = new TXmlReader(Application.StartupPath + "\\Lang\\" + language + ".xml");
LsNext = reader.GetString("HTMLEXP", "Next", "Next");
LsPrev = reader.GetString("HTMLEXP", "Prev", "Previous");
LsThumbs = reader.GetString("HTMLEXP", "Thumbs", "Thumbnails");
LsVPO = reader.GetString("HTMLEXP", "VPO", "Created with Virtual Photo Organizer");
LsDesc = reader.GetString("HTMLEXP", "Desc", "Description:");
reader.Close();
}
catch {
// use defaults
LsPrev = "Previous";
LsNext = "Next";
LsThumbs = "Thumbnails";
LsVPO = "Created with Virtual Photo Organizer";
LsDesc = "Description:";
}
}
/// <summary>
/// initiates the export process (with copying)
/// </summary>
public void Export(string destPath, string mainAlbumName, Color bgColor, Color textColor) {
Cancel = false;
// show the dialog and hook into its cancel event
Pd.CancelProcess += new VirtualPhotoOrganizer.Dialogs.ProgressDialog.Cancel(Pd_CancelProcess);
Pd.Show();
// create the dest directory if it doesn't exist
if (!Directory.Exists(destPath))
Directory.CreateDirectory(destPath);
if (Cancel == false) {
MaxUpdate(Photos.Count, LsCopy);
CopyPhotos(destPath);
}
if (Cancel == false) {
MaxUpdate(Photos.Count, LsThumb);
CreateThumbs(destPath);
}
if (Cancel == false) {
MaxUpdate(Photos.Count, LsHTML);
WriteHTML(destPath, mainAlbumName, bgColor, textColor);
}
// close the dialog, hook out of its cancel event and reset Close
Pd.CancelProcess -= new VirtualPhotoOrganizer.Dialogs.ProgressDialog.Cancel(Pd_CancelProcess);
ProcessDone();
}
/// <summary>
/// initiates the export process (with resizing)
/// </summary>
public void Export(string destPath, string mainAlbumName, Color bgColor, Color textColor, int width, int height, int quality, InterpolationMode intMode) {
Cancel = false;
// show the dialog and hook into its cancel event
Pd.CancelProcess += new VirtualPhotoOrganizer.Dialogs.ProgressDialog.Cancel(Pd_CancelProcess);
Pd.Show();
// create the dest directory if it doesn't exist
if (!Directory.Exists(destPath))
Directory.CreateDirectory(destPath);
if (Cancel == false) {
MaxUpdate(Photos.Count, LsResize);
Resize(destPath, width, height, quality, intMode);
}
if (Cancel == false) {
MaxUpdate(Photos.Count, LsThumb);
CreateThumbs(destPath);
}
if (Cancel == false) {
MaxUpdate(Photos.Count, LsHTML);
WriteHTML(destPath, mainAlbumName, bgColor, textColor);
}
// close the dialog, hook out of its cancel event and reset Close
Pd.CancelProcess -= new VirtualPhotoOrganizer.Dialogs.ProgressDialog.Cancel(Pd_CancelProcess);
ProcessDone();
}
/// <summary>
/// initiates the export process (with diffQSave)
/// </summary>
public void Export(string destPath, string mainAlbumName, Color bgColor, Color textColor, int quality) {
Cancel = false;
// show the dialog and hook into its cancel event
Pd.CancelProcess += new VirtualPhotoOrganizer.Dialogs.ProgressDialog.Cancel(Pd_CancelProcess);
Pd.Show();
// create the dest directory if it doesn't exist
if (!Directory.Exists(destPath))
Directory.CreateDirectory(destPath);
if (Cancel == false) {
MaxUpdate(Photos.Count, LsResize);
DiffQSave(destPath, quality);
}
if (Cancel == false) {
MaxUpdate(Photos.Count, LsThumb);
CreateThumbs(destPath);
}
if (Cancel == false) {
MaxUpdate(Photos.Count, LsHTML);
WriteHTML(destPath, mainAlbumName, bgColor, textColor);
}
// close the dialog, hook out of its cancel event and reset Close
Pd.CancelProcess -= new VirtualPhotoOrganizer.Dialogs.ProgressDialog.Cancel(Pd_CancelProcess);
ProcessDone();
}
#region Copying
private void CopyPhotos(string destPath) {
// create the photos directory if it doesn't exist
if (!Directory.Exists(destPath + "\\Img"))
Directory.CreateDirectory(destPath + "\\Img");
FileInfo fi;
string dest;
int i = 0;
foreach (Photo.Photo p in Photos) {
fi = new FileInfo(p.Path);
dest = destPath + "\\Img\\" + fi.Name;
// find out if the file exists and ask if the user wishes to overwrite
if (File.Exists(dest)) {
if (MessageBox.Show(LsOverwrite, fi.Name, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
fi.CopyTo(dest, true);
} else
fi.CopyTo(dest);
// update the photo's path and thumbs dir
p.Path = dest;
p.Thumbnail = destPath + "\\Thumbs\\th_" + fi.Name;
Application.DoEvents();
if (Cancel == true)
return;
// update the progress dialog
ProgressUpdate(++i);
}
}
#endregion
#region Resizing
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -