Use the aspjpeg component to generate a thumbnail

Source: Internet
Author: User
/**/ ///   <Summary>
/// Use aspjpg to generate a thumbnail
///   </Summary>
///   <Param name = "originalpicpath"> Original Image path, virtual path, such as "images/aa.jpg" </Param>
///   <Param name = "thumbnailpicpath"> Thumbnail storage path, such as "images /" </Param>
///   <Param name = "maxwidth"> Max thumbnail width </Param>
///   <Param name = "maxheight"> Maximum thumbnail height </Param>
///   <Returns> Returns the virtual path of the thumbnail file. </Returns>
Public   String Thumbpic ( String Originalpicpath, String Thumbnailpicpath, Int Maxwidth, Int Maxheight)
{
Aspjpeglib. iaspjpeg objjpeg =   New Aspjpeglib. aspjpeg ();

// Compute path to source Image
String strpath = Server. mappath (originalpicpath );

// Open source Image
Objjpeg. Open (strpath );

Thumbnailpicpath + = System. datetime. Now. Date. to1_datestring () +   " . "   + System. datetime. Now. Minute. tostring () +   " . "   + System. datetime. Now. Second. tostring () +   " . "   + System. datetime. Now. millisecond. tostring () +   " . "   + Objjpeg. originalformat;

// Ensure that the source image is scaled proportionally to the thumbnail under the source image.
Decimal Width = 0 ;
Decimal Height = 0 ;
If (Objjpeg. originalwidth < Objjpeg. originalheight)
{
Height=Maxheight;
Width=Convert. toint32 (maxheight*Objjpeg. originalwidth/Objjpeg. originalheight );
}
Else
{
Width=Maxwidth;
Height=Convert. toint32 (maxwidth*Objjpeg. originalheight/Objjpeg. originalwidth );
}

Objjpeg. Width = Convert. toint32 (width );
Objjpeg. Height = Convert. toint32 (height );

// Create thumbnail and save it to disk
Objjpeg. Save (server. mappath (thumbnailpicpath ));

Return Thumbnailpicpath;
}

Aspjpeg download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.