Save thumbnails in multiple paths and formats

Source: Internet
Author: User

Using System;
Using System. Drawing;

Namespace PubLib
{
/// <Summary>
/// Summary of PicShow.
/// </Summary>
Public class PicShow
{
Public PicShow ()
{
//
// TODO: add the constructor logic here
//
}

// Check whether the image file exists
Public static string ViewPIC (string PicPath, string PicName)
{

String BigPic = Checks. HM_PHYSICSROOT + "MoviePIC/" + Checks. HM_PICROOTPATH + "/" + PicName;
String SmlPic = Checks. HM_PHYSICSROOT + "MoviePIC/" + PicPath + "/" + PicName;

If (null = PicName | false = System. IO. File. Exists (BigPic) // The big image name is null or the File does not exist
PicName = "nopic.jpg ";

String OutPic = "MoviePIC/" + PicPath + "/" + PicName;

If (! System. IO. File. Exists (SmlPic) // The image does not exist.
{
CreatePIC (PicPath, PicName );
Return OutPic;
}
Return OutPic;
}

// Create a thumbnail
Public static void CreatePIC (string PicPath, string PicName)
{
Int iWidth, iHeight;
If (null! = PicPath & PicPath. IndexOf ("X")> 1)
{
Char [] spliter = {X };
String [] aPicPath = PicPath. Split (spliter, 2 );
IWidth = Int32.Parse (aPicPath [0]);
IHeight = Int32.Parse (aPicPath [1]);

String BigPic = Checks. HM_PHYSICSROOT + "MoviePIC/" + Checks. HM_PICROOTPATH + "/" + PicName;
String SmlPic = Checks. HM_PHYSICSROOT + "MoviePIC/" + PicPath + "/" + PicName;
Image BigImage = Image. FromFile (BigPic );
Image SmlImage = BigImage. GetThumbnailImage (iWidth, iHeight, null, new System. IntPtr ());
SmlImage. Save (SmlPic, System. Drawing. Imaging. ImageFormat. Jpeg );
BigImage. Dispose ();
SmlImage. Dispose ();
}
}
}
}

Checks. HM_PHYSICSROOT is a static variable that is the root path of the system. How do you obtain it? You can write a path to it. Although not flexible, it is still simple. That's what I did.

Public static string HM_PHYSICSROOT = AppDomain. CurrentDomain. BaseDirectory;

(In fact, it's also simple to figure out Xuan XU :~)

Multi-path, that is, a little scary. You can specify a path when generating a thumbnail. That is, the PicPath parameter needs to be manually specified. If multiple formats are entered, the size can be adjusted. My method is to set the path to the size. For example, the image path of 200*300 is named x300. Of course, you must specify the original image path. Otherwise, you will get the image from there to generate a thumbnail. This Checks. HM_PICROOTPATH can only be handwritten. There is no way. It will not be changed once it is written.


Related Article

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.