>Hi,
>
[quoted text clipped - 10 lines]
>
>TIA
One of my programs does a similar task, it creates thumbnails to a
standard size, where the longest dimension of the thumbnail is fixed.
There is a certain amount of other code to check that it does not
create thumbnails of thumbnails (it is from a batch process that deals
with groups of files). Careful with line wrap, this is cut and pasted
from my code and was not formatted for usenet.
rossum
// ==== Code Begin ====
const double thumbSize = 175.0; // Longer dimension of thumbnails
/// <summary>
/// Creates a thumbnail of an image file in the same directory.
/// </summary>
/// <param name="jpeg">The image file from which to create the
thumbnail.</param>
/// <returns>True if a thumbnail was created, false
otherwise.</returns>
private bool makeThumbnail(FileInfo jpeg) {
StringBuilder thumbName = new StringBuilder(jpeg.FullName);
thumbName.Replace(m_targetExtn, m_thumbExtn);
if (File.Exists(thumbName.ToString())) {
MessageBox.Show("Warning: " + jpeg.Name + " thumbnail already
exists.",
"Thumbnail Batch",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
return false;
} // end if
// Check not already a thumbnail
if (jpeg.Name.Contains(m_thumbExtn)) {
return false;
} // end if
Image img = Image.FromFile(jpeg.FullName);
if (img.Height <= thumbSize || img.Width <= thumbSize) {
img.Dispose();
return false;
} // end if
// Scale the thumbnail
int newWidth, newHeight;
if (img.Height > img.Width) {
newHeight = (int)thumbSize;
newWidth = (int)(img.Width * thumbSize / img.Height);
}
else {
newWidth = (int)thumbSize;
newHeight = (int)(img.Height * thumbSize / img.Width);
} // end if
Image thumb = img.GetThumbnailImage(newWidth, newHeight, null,
(IntPtr)null);
thumb.Save(thumbName.ToString());
img.Dispose();
thumb.Dispose();
return true;
} // end makeThumbnail()
// ==== Code End ====
Andrew Thompson - 15 Oct 2007 11:51 GMT
...
> ...Careful with line wrap, this is cut and pasted
> from my code and was not formatted for usenet.
A tool designed to help with that.
<http://www.physci.org/twc.jnlp>
Andrew T.
Here's a ready to use method I wrote for resizing pictures and maintaing
their aspect ratio:
http://www.geekpedia.com/code7_Method-for-resizing-pictures-with-aspect-ratio.html
It works with various formats.
Good luck!
Andrew
> Hi,
>
[quoted text clipped - 10 lines]
>
> TIA