国产探花免费观看_亚洲丰满少妇自慰呻吟_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( );
        }
    }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 新蔡县| 临海市| 莫力| 儋州市| 阿荣旗| 石景山区| 乳山市| 靖西县| 库尔勒市| 安多县| 岐山县| 清丰县| 浦北县| 黔西县| 金沙县| 遂川县| 郯城县| 乌鲁木齐市| 芮城县| 屏东市| 防城港市| 赣州市| 陇川县| 余姚市| 临夏县| 如东县| 恩施市| 南华县| 汽车| 三都| 沧州市| 杭州市| 太康县| 常宁市| 临朐县| 体育| 永川市| 图片| 东乌珠穆沁旗| 南川市| 肥城市|