C thumbnail multi path multi format saved instance
- 2020-05-17 06:14:17
- OfStack
using System;
using System.Drawing;
namespace PubLib
{
/// <summary>
/// PicShow A summary of.
/// </summary>
public class PicShow
{
public PicShow()
{
//
// TODO: Add the constructor logic here
//
}
// Find out if 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 large image name is empty or the file does not exist
PicName = "nopic.jpg";
string OutPic = "MoviePIC/"+PicPath+"/"+PicName;
if (!System.IO.File.Exists(SmlPic)) // The lookup thumbnail does not exist
{
CreatePIC(PicPath, PicName);
return OutPic;
}
return OutPic;
}
// Create thumbnails
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 which is the root of the system. How do you get it? It's actually pretty easy you could just write a path to it. It's not flexible but it's simple. Here's what I did
public static string HM_PHYSICSROOT = AppDomain.CurrentDomain.BaseDirectory;
(in fact, it is also simple: ~)
Multiple paths, which is a little scary, you can specify one path when you generate the thumbnail. This is the parameter PicPath that you need to specify by hand. In multi-format terms, it can be resized. My method is that the path is the size, such as 200*300 image path is called 200X300 hey hey, of course, to specify a picture of the original path, or from there to get the image to generate thumbnail ah. This Checks.HM_PICROOTPATH can only be written by hand. I'm not going to change it once I write it.