Thumbnail Generation

M

mo

Hi,
I have the following code to create a thumbnail from the input stream

System.Drawing.Image source;
source=System.Drawing.Image.FromStream(new
System.IO.MemoryStream(myData));
System.Drawing.Image image = source.GetThumbnailImage
150,150,null,IntPtr.Zero);
MemoryStream ms = new MemoryStream();
ImageFormat thisformat=image.RawFormat;
Bitmap imagebitmap = new Bitmap(image,150,150);
imagebitmap.Save(ms,thisformat);
ms.Seek(0,SeekOrigin.Begin);
byte[] SmallmyData = new byte[ms.Length];
FileStream newFile = new FileStream(strPath, FileMode.Create);
newFile.Write(Buffer, 0, SmallmyData.Length);
newFile.Close();

Two problems I have
1) imagebitmap.Save(ms,thisformat); line faults and cannot find the
value for thisformat (It works if I replace it with ImageFormat.Jpeg)
2) the file that gets created is corrupt.

ANy help is greatly appreciated.

Thanks,
Mo
 
R

Rick Strahl [MVP]

Try this code:

http://west-wind.com/weblog/posts/283.aspx

and

http://west-wind.com/weblog/posts/626.aspx


In addition to working <g>, the above code doesn't use GetThumbnailImage
which generally does a pretty poor job of creating thumbnails. The second
post talks about adding a switch for the InterpolationMode to further
enhance image quality of a resized image.

Regards,

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
http://www.west-wind.com/wwThreads/
 

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,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top