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( );
}
}
新闻热点
疑难解答