Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

Create thumbnails without loading entire file into memory

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Phil Johnson - 25 Apr 2008 17:02 GMT
Hi,  

I am working on an ASP.NET 1.1 application that creates thumbnails using the
code below.

Problem is that the code loads an entire file into memory to instantiate the
image (file.Data is a memorystream).

This obviously isnt feasible for large files.  Does anybody know of a
thumbnail component that doesn't load the entire file into memory?

Image fullImage = Image.FromStream(file.Data);
            // maximum height or width is 100
           
            double imgWidth = Convert.ToDouble(fullImage.Width);
            double imHeight = Convert.ToDouble(fullImage.Height);
           
            double divisor = 0;
            if(fullImage.Height > fullImage.Width)
            {
                divisor = (100/imHeight);
            }
            else
            {
                divisor = (100/imgWidth);
            }           
            Image thumbnail =
fullImage.GetThumbnailImage(Convert.ToInt32(imgWidth*divisor),
                Convert.ToInt32(imHeight*divisor),
                new System.Drawing.Image.GetThumbnailImageAbort(rtnVal.ThumbnailCallback),
                IntPtr.Zero);

Signature

Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com

Peter Bromberg [C# MVP] - 25 Apr 2008 19:51 GMT
Somebody correct me if I'm wrong, but I believe you need the entire image
object in order to correctly create a thumbnail from it - at least with the
GetThumbnailImage method.
-- Pete
To be a success, arm yourself with the tools you need and learn how to use
them.

Site: http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://ittyurl.net

> Hi,  
>
[quoted text clipped - 27 lines]
>                 new System.Drawing.Image.GetThumbnailImageAbort(rtnVal.ThumbnailCallback),
>                 IntPtr.Zero);
George Ter-Saakov - 25 Apr 2008 19:59 GMT
I would create thumbnail once and cache it on disk. Next time I would hit
the cached file.
Probably you need to check "Last Modified" date of the original file and the
thumbnail so if original has been changed then recreate thumbnail.

-------------------------------------------------------------
I belive that JPEG images allows to have thumbnails inside of the JPEG
file's data structure.
But it will be much harder to get/put that from/to there rather than do it
with separate file.....

George.

> Somebody correct me if I'm wrong, but I believe you need the entire image
> object in order to correctly create a thumbnail from it - at least with
[quoted text clipped - 42 lines]
>> System.Drawing.Image.GetThumbnailImageAbort(rtnVal.ThumbnailCallback),
>> IntPtr.Zero);
Phil Johnson - 25 Apr 2008 20:57 GMT
Thanks for the responses.

I suspected you might need to load the whole file into memory which I was
hoping to avoid.... we let people upload files up to 1 GB and if that loads
into memory it will kill the server.

We get files in by buffering them from the request stream to a temporary
file then buffering the data from the temporary file into the data base so we
never have more than about 8k of data in memory at any one time.

We might just have to cap the size of files that we can thumbnail in that
case.

Signature

Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com

> I would create thumbnail once and cache it on disk. Next time I would hit
> the cached file.
[quoted text clipped - 55 lines]
> >> System.Drawing.Image.GetThumbnailImageAbort(rtnVal.ThumbnailCallback),
> >> IntPtr.Zero);

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.