📄 htmlexporter.cs
字号:
/// <summary>
/// Resizes the photos to a given max size and saves them under a given quality
/// </summary>
private void Resize(string destPath, int width, int height, int quality, InterpolationMode intMode) {
// 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;
Resizer resizer = new Resizer();
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)
resizer.Resize(p.Path, dest, width, height, quality, intMode);
} else
resizer.Resize(p.Path, dest, width, height, quality, intMode);
// 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);
}
}
/// <summary>
/// Saves the photod with the specified quality
/// </summary>
private void DiffQSave(string destPath, int quality) {
// 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;
JpegSaver js = new JpegSaver();
bool doSave;
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)
doSave = true;
else
doSave = false;
} else
doSave = true;
if (doSave == true) {
Image img = Bitmap.FromFile(p.Path);
Bitmap b = new Bitmap(img);
js.SaveJpeg(dest, b, quality);
b.Dispose();
img.Dispose();
}
// 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 Thumbnails
private void CreateThumbs(string destPath) {
// check if the dir exists and create it if necessarry
if (!Directory.Exists(destPath + "\\Thumbs"))
Directory.CreateDirectory(destPath + "\\Thumbs");
int i = 0;
Photo.Resizer resizer = new Resizer();
// create the thumbs
foreach (Photo.Photo p in Photos) {
if (File.Exists(p.Thumbnail)) {
if (MessageBox.Show(LsOverwrite, p.Thumbnail, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
resizer.CreateThumbnailWoBorders(p.Path, p.Thumbnail);
} else
resizer.CreateThumbnailWoBorders(p.Path, p.Thumbnail);
Application.DoEvents();
if (Cancel == true)
return;
// update the progress dialog
ProgressUpdate(++i);
}
}
#endregion
#region WriteHTML
/// <summary>
/// writes the html album's html files
/// </summary>
private void WriteHTML(string destPath, string mAlbName, Color bgColor, Color textColor) {
WriteMainAlbum(destPath, mAlbName, bgColor, textColor);
// write each photo's html file
FileInfo fi;
string path;
string prev;
string next;
int i = 0;
foreach (Photo.Photo p in Photos) {
// get the names of the previous and next photos
if (i == 0)
prev = "";
else {
fi = new FileInfo(Photos[i - 1].Path);
prev = fi.Name + ".htm";
}
if (i == Photos.Count - 1)
next = "";
else {
fi = new FileInfo(Photos[i + 1].Path);
next = fi.Name + ".htm";
}
// get the name of the current photo and write an html file for it
fi = new FileInfo(p.Path);
path = destPath + '\\' + fi.Name + ".htm";
if (File.Exists(path)) {
if (MessageBox.Show(LsOverwrite, fi.Name + ".htm", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
WritePhoto(path, prev, next, mAlbName, bgColor, textColor, "Img/" + fi.Name, "Thumbs/th_" + fi.Name, p.Title, p.Description);
} else
WritePhoto(path, prev, next, mAlbName, bgColor, textColor, "Img/" + fi.Name, "Thumbs/th_" + fi.Name, p.Title, p.Description);
Application.DoEvents();
if (Cancel == true)
return;
// update the progress dialog
ProgressUpdate(++i);
}
}
/// <summary>
/// writes an html file for the specified photo
/// </summary>
private void WritePhoto(string path, string prev, string next, string mAlbum, Color bgColor, Color textColor, string photo, string thumb, string name, string desc) {
// write the beginning of the html file
string album = "<html><head><title>" + HttpUtility.HtmlEncode(name) + "</title><style>body {font-family:Verdana; font-color:" + ColorTranslator.ToHtml(textColor) + ";}</style></head>";
album += "\n<body bgcolor=\"" + ColorTranslator.ToHtml(bgColor) + "\"><font color=\"" + ColorTranslator.ToHtml(textColor) + "\"><center><h3>" + HttpUtility.HtmlEncode(name) + "</h3>";
// write the main content
album += "<table width=100%><tr><td align=left>";
if (prev != "")
album += "<h4><a href=\"" + prev + "\">" + HttpUtility.HtmlEncode(LsPrev) + "</a></h4>";
album += "</td><td align=center></td><td align=right>";
if (next != "")
album += "<h4><a href=\"" + next + "\">" + HttpUtility.HtmlEncode(LsNext) + "</a></h4>";
album += "</td></tr></table><br><img src=\"" + photo + "\">";
if (this.ExpDesc == true)
album += "<p align=left><b>" + LsDesc + "</b><br>" + HttpUtility.HtmlEncode(desc) + "</p>";
album += "<br><a href=\"" + mAlbum + "\">" + HttpUtility.HtmlEncode(LsThumbs) + "</a>";
album += "<br><br>\n<h4><small><a href=\"" + URL + "\">" + HttpUtility.HtmlEncode(LsVPO) + "</a></h4></center></font></body></html>";
StreamWriter sw = new StreamWriter(path, false);
sw.Write(album);
sw.Close();
}
/// <summary>
/// writes the main album file
/// </summary>
private void WriteMainAlbum(string destPath, string mAlbName, Color bgColor, Color textColor) {
bool writeAlbum;
if (File.Exists(destPath + '\\' + mAlbName)) {
if (MessageBox.Show(LsOverwrite, mAlbName, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
writeAlbum = true;
else
writeAlbum = false;
} else
writeAlbum = true;
if (writeAlbum == true) {
// write the beginning of the html file
string album = "<html><head><title>Virtual Photo Organizer HTML Album</title><style>body {font-family:Verdana; font-color:" + ColorTranslator.ToHtml(textColor) + ";}</style></head>";
album += "\n<body bgcolor=\"" + ColorTranslator.ToHtml(bgColor) + "\"><font color=\"" + ColorTranslator.ToHtml(textColor) + "\"><center><h3>Virtual Photo Organizer HTML Album</h3>";
album += "\n<table>\n<tr>";
// write the thumbnail table
int columnCount = 0; // counts the number of columns we have in one line
FileInfo fi;
foreach (Photo.Photo p in Photos) {
// if we have 5 photos is a row insert a new row
if (columnCount % 5 == 0 && columnCount != 0)
album += "</tr><tr>";
// write the column with the thumb
fi = new FileInfo(p.Path);
album += "<td align=center valign=bottom><a href=\"" + fi.Name + ".htm\"><img src=\"Thumbs/th_" + fi.Name + "\"><div style=\"text-align: center\">" + HttpUtility.HtmlEncode(p.Title) + "</div></a></td>";
columnCount++;
}
album += "</tr></table><br><br>\n<h4><small><a href=\"" + URL + "\">" + HttpUtility.HtmlEncode(LsVPO) + "</a></h4></font></center></body></html>";
StreamWriter sw = new StreamWriter(destPath + '\\' + mAlbName, false);
sw.Write(album);
sw.Close();
}
}
#endregion
private void Pd_CancelProcess() {
Cancel = true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -