Search results for 'thumbnail'. 2 post(s) found.

  1. 2009/06/03 How to resize image ?
  2. 2007/10/04 Creating thumbnail images
2009/06/03 19:57

How to resize image ?


Here's the simple example can resizing source image:

<%@ page import="java.io.*,
                java.awt.*,
                java.awt.image.*,
                javax.swing.*,
                com.sun.image.codec.jpeg.*"
    contentType="text/html;charset=MS949" %>
<%!
    public static void createthumbnail(String soruce, String target, int targetW) throws Exception
    {
        Image imgSource = new ImageIcon(soruce).getImage();

        int oldW = imgSource.getWidth(null);
        int oldH = imgSource.getHeight(null);

        int newW = targetW;
        int newH = (targetW * oldH) / oldW;

        Image imgTarget = imgSource.getScaledInstance(newW, newH, Image.SCALE_SMOOTH);

        int pixels[] = new int[newW * newH];

        PixelGrabber pg = new PixelGrabber(imgTarget, 0, 0, newW, newH, pixels, 0, newW);
        pg.grabPixels();

        BufferedImage bi = new BufferedImage(newW, newH, BufferedImage.TYPE_INT_RGB);
        bi.setRGB(0, 0, newW, newH, pixels, 0, newW);

        FileOutputStream fos = new FileOutputStream(target);

        JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(fos);

        JPEGEncodeParam jep = jpeg.getDefaultJPEGEncodeParam(bi);
        jep.setQuality(1, false);

        jpeg.encode(bi, jep);

        fos.close();
    }
%>
<%
    createthumbnail("c:/inetpub/c/big.jpg","c:/inetpub/c/big_result.jpg",320);
%>

Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.

2007/10/04 08:11

Creating thumbnail images


Suppose you have a Web Form where uploading of files is enabled, using the HtmlInputFile HTML control, and a user is uploading an image. If you accept only images of a specified size, you might need to shrink the uploaded image / create a thumnail.
Here's how to create thumbnail images in ASP.NET Delphi web applications.

procedure Generatethumbnail(const FileName : string; const ImageStream : Stream; const tWidth, tHeight : Double) ;
var
   g : System.Drawing.Image;
   thumbSize : Size;
   imgOutput : Bitmap;
   imgStream : MemoryStream;
begin
//This function creates the thumbnail image and returns the
//image created in Byte() format

   g := System.Drawing.Image.FromStream(ImageStream) ;
   thumbSize := NewThumbSize(g.Width, g.Height, tWidth, tHeight) ;

   imgOutput := Bitmap.Create(g, thumbSize.Width, thumbSize.Height) ;
   imgStream := MemoryStream.Create;
   imgOutput.Save(imgStream, g.RawFormat) ;
   imgOutput.Save(Path.Combine('c:\LocationOnServer',FileName)) ;
   g.Dispose;
   imgOutput.Dispose;
end;

function NewThumbSize(const currentwidth, currentheight, newWidth, newHeight : Double) : Size;
var
   tempMultiplier : Double;
   NewSize : Size;
begin
   if currentheight > currentwidth Then
    tempMultiplier := newHeight / currentheight
   else
    tempMultiplier := newWidth / currentwidth;

   NewSize := Size.Create(Convert.ToInt32(currentwidth * tempMultiplier), Convert.ToInt32(currentheight * tempMultiplier)) ;
   Result := NewSize;
end;

//Usage:
Generatethumbnail('ThumbnameOnServer', ImageFile.PostedFile.InputStream, thumbWidth, thumbHeight) ;

//Where
//ImageFile : System.Web.UI.HtmlControls.HtmlInputFile;
Trackback 6 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject Buy xanax with no prescription.

    Tracked from Xanax. 2009/02/13 22:34 delete

    Buy 180 xanax. Xanax. No prescription xanax. Xanax cocktail. Buy cheap xanax without prescription. Side effects of xanax.

  2. Subject Fetish town free scat porn and fetish sex sites.

    Tracked from Scat porn. 2009/03/31 14:17 delete

    Scat porn archive cringe humor forum. Scat porn. Porn movie scat sex. Scat porn galleries.

  3. Subject Free zoo porn movies.

    Tracked from Free zoo porn vids. 2009/03/31 17:59 delete

    Animal sex zoo free porn bestiality horse.

  4. Subject different money making ideas

    Tracked from moneyideas 2010/01/28 23:26 delete

    moneyideas

  5. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 07:43 delete

    moneyideas

  6. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:41 delete

    moneyideas