how to produce thumbnails

D

Daniel

hi,
I have a whole lot of pictures needed to transform to the thumbnails to
display on the web, it there any easy to do?

Thanks.
 
F

Felipe

Here's some code I've been playing around with. It creates square thumbs,
but could easily be modified to create proportional...

private void CreateThumbnail(string pathToFullSizeImage, string
pathToThumbnailImage, int sizeToCreate) {
try {
int iWidth = 0;
int iHeight = 0;
string strFilename = pathToFullSizeImage;
int dotPlace = strFilename.LastIndexOf(".");
string fileType = strFilename.Substring((dotPlace + 1),
(strFilename.Length - (dotPlace + 1))).ToUpper();

if (sizeToCreate == 1) {
iWidth = 80;
iHeight = 80;
}
else {
iWidth = 130;
iHeight = 130;
}

System.IO.FileStream fs = new System.IO.FileStream(pathToFullSizeImage,
System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.Drawing.Image objThumbnail =
System.Drawing.Image.FromStream(fs).GetThumbnailImage(iWidth, iHeight, null,
IntPtr.Zero);
// DO NOT USE THE FOLLOWING LINE (in place of the previous line) because
Image.FromFile() keeps the file open. This is why we open the file via a
stream - a stream can be closed.
// System.Drawing.Image objThumbnail =
System.Drawing.Image.FromFile(strFilename).GetThumbnailImage(iWidth,
iHeight, null, IntPtr.Zero);

// Set the ContentType correctly
if (fileType == "JPG" || fileType == "JPEG") {
objThumbnail.Save(pathToThumbnailImage, ImageFormat.Jpeg);
}
else {
objThumbnail.Save(pathToThumbnailImage, ImageFormat.Gif);
}

objThumbnail.Dispose();
fs.Close();

}

catch (Exception ex) {
if (!(ex is OOPS.DalException)) {
OOPS.WriteErrorInfo(ex, "");
}
}
}
 
D

Daniel

Felipe, i really appreciate your help.


Here's some code I've been playing around with. It creates square thumbs,
but could easily be modified to create proportional...

private void CreateThumbnail(string pathToFullSizeImage, string
pathToThumbnailImage, int sizeToCreate) {
try {
int iWidth = 0;
int iHeight = 0;
string strFilename = pathToFullSizeImage;
int dotPlace = strFilename.LastIndexOf(".");
string fileType = strFilename.Substring((dotPlace + 1),
(strFilename.Length - (dotPlace + 1))).ToUpper();

if (sizeToCreate == 1) {
iWidth = 80;
iHeight = 80;
}
else {
iWidth = 130;
iHeight = 130;
}

System.IO.FileStream fs = new System.IO.FileStream(pathToFullSizeImage,
System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.Drawing.Image objThumbnail =
System.Drawing.Image.FromStream(fs).GetThumbnailImage(iWidth, iHeight,
null,
IntPtr.Zero);
// DO NOT USE THE FOLLOWING LINE (in place of the previous line)
because
Image.FromFile() keeps the file open. This is why we open the file via a
stream - a stream can be closed.
// System.Drawing.Image objThumbnail =
System.Drawing.Image.FromFile(strFilename).GetThumbnailImage(iWidth,
iHeight, null, IntPtr.Zero);

// Set the ContentType correctly
if (fileType == "JPG" || fileType == "JPEG") {
objThumbnail.Save(pathToThumbnailImage, ImageFormat.Jpeg);
}
else {
objThumbnail.Save(pathToThumbnailImage, ImageFormat.Gif);
}

objThumbnail.Dispose();
fs.Close();

}

catch (Exception ex) {
if (!(ex is OOPS.DalException)) {
OOPS.WriteErrorInfo(ex, "");
}
}
}
 
K

Kevin Spencer

A good pair of thumbnail clippers.

;-)

Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
F

Felipe

Now I know why you're an MVP : )




Kevin Spencer said:
A good pair of thumbnail clippers.

;-)

Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top