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.