how to produce thumbnails

Discussion in 'ASP .Net' started by Daniel, Jul 15, 2004.

  1. Daniel

    Daniel Guest

    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.
     
    Daniel, Jul 15, 2004
    #1
    1. Advertising

  2. Daniel

    Felipe Guest

    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, "");
    }
    }
    }


    "Daniel" <> wrote in message
    news:eek:psa62m7naxo301l@dev-02...
    > 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.
     
    Felipe, Jul 15, 2004
    #2
    1. Advertising

  3. Daniel

    Mark Jerde Guest

    Daniel wrote:
    > 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.


    How about "Easy Thumbnails" (freeware) from
    http://www.fookes.com/

    <g>

    -- Mark
     
    Mark Jerde, Jul 15, 2004
    #3
  4. Daniel

    Daniel Guest

    Felipe, i really appreciate your help.


    On Thu, 15 Jul 2004 13:01:10 -0700, Felipe <> wrote:

    > 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, "");
    > }
    > }
    > }
    >
    >
    > "Daniel" <> wrote in message
    > news:eek:psa62m7naxo301l@dev-02...
    >> 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.

    >
    >
     
    Daniel, Jul 15, 2004
    #4
  5. A good pair of thumbnail clippers.

    ;-)

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

    "Daniel" <> wrote in message
    news:eek:psa62m7naxo301l@dev-02...
    > 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.
     
    Kevin Spencer, Jul 15, 2004
    #5
  6. Daniel

    Felipe Guest

    Now I know why you're an MVP : )




    "Kevin Spencer" <> wrote in message
    news:...
    > A good pair of thumbnail clippers.
    >
    > ;-)
    >
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > Big things are made up
    > of lots of little things.
    >
    > "Daniel" <> wrote in message
    > news:eek:psa62m7naxo301l@dev-02...
    > > 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.

    >
    >
     
    Felipe, Jul 15, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Franco Gustavo

    OpenDialog and thumbnails

    Franco Gustavo, Aug 27, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,105
    Franco Gustavo
    Aug 27, 2003
  2. Kenneth Keeley

    Displaying PDF Thumbnails

    Kenneth Keeley, Jul 3, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    447
    Kenneth Keeley
    Jul 3, 2003
  3. Espen Evje
    Replies:
    1
    Views:
    398
    Espen Evje
    Jul 11, 2003
  4. Rick Spiewak

    Re: Create thumbnails on the fly

    Rick Spiewak, Jul 24, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    505
    David W. Simmonds
    Jul 25, 2003
  5. Replies:
    5
    Views:
    479
    Luc The Perverse
    Oct 27, 2006
Loading...

Share This Page