国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

使用C#批量生成縮略圖的工具源代碼

2023-05-16 12:36:05
字體:
來源:轉載
供稿:網友

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.IO;
using System.Diagnostics;
using System.Windows.Forms.Design;
namespace Image
{
    public class ImageConvert 
    {
        public static void ShowThumbnail( string oldfile, 
        string newfile, 
        int h, 
        int w )  
        {
            System.Drawing.Image img = System.Drawing.Image.FromFile( oldfile );
            System.Drawing.Image.GetThumbnailImageAbort myCallback = new System.Drawing.Image.GetThumbnailImageAbort( ThumbnailCallback );
            
            int oldh = img.Height;
            
            int oldw = img.Width;
            
            int newh,neww;
            double h1 = oldh*1.0/h;
            double w1 = oldw*1.0/w;
            double f = ( h1>w1 )? h1:w1;
            if( f < 1.0 )
            {
                newh = oldh;
                neww = oldw;
            }
            else
            {
                newh = ( int )( oldh/f );
                neww = ( int )( oldw/f );
            }
            System.Drawing.Image myThumbnail = img.GetThumbnailImage( neww, newh, myCallback, IntPtr.Zero );
            myThumbnail.Save( newfile, System.Drawing.Imaging.ImageFormat.Jpeg );
            img.Dispose( );
            myThumbnail.Dispose( );
        }
        
        private static bool ThumbnailCallback( )  
        {
            return false;
        }
    }
    
    public class FolderDialog : FolderNameEditor 
    {
        FolderNameEditor.FolderBrowser fDialog = new System.Windows.Forms.Design.FolderNameEditor.FolderBrowser( );
        
        public FolderDialog( )  
        {
        }
        
        public DialogResult DisplayDialog( )  
        {
            return DisplayDialog( "請選擇一個文件夾" );
        }
        
        public DialogResult DisplayDialog( string description )  
        {
            fDialog.Description = description;
            return fDialog.ShowDialog( );
        }
        
        public 
        string Path  
        {
            get
            {
                return fDialog.DirectoryPath;
            }
        }
        ~FolderDialog( )  
        {
            fDialog.Dispose( );
        }
    }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安溪县| 龙州县| 阜新市| 临泽县| 原阳县| 祁东县| 木里| 安徽省| 徐州市| 蓬安县| 多伦县| 铁岭县| 车险| 冕宁县| 宿迁市| 黎城县| 仙桃市| 澳门| 福泉市| 安国市| 辽宁省| 兴山县| 东源县| 张家港市| 安康市| 建昌县| 简阳市| 资溪县| 明水县| 南岸区| 将乐县| 安龙县| 阿拉善右旗| 伊通| 绥宁县| 湖南省| 泰和县| 临西县| 柳州市| 凌海市| 石渠县|