Creating thumbnail images | |||
| |||
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; Tags: BitConverter Delphi Generate Thumbnail from Image Stream Thumbnail creation from image stream create a thumbnail thumbnail | |||
| |||
| |||
Login for comment |