C# 缩小图像的尺寸

C# 缩小图像的尺寸,c#,image,C#,Image,如何在C#中降低图像的维数?我在.NET1.1中工作 示例:将尺寸800x600减小到400x400,需要调整图像大小 System.Drawing.Image imgToResize = null; Bitmap bmpImage = null; Graphics grphImage = null; try { imgToResize = System.Drawing.Image.FromFile ( "image path" ); bmpImage = new Bitma

如何在C#中降低图像的维数?我在.NET1.1中工作


示例:将尺寸800x600减小到400x400,需要调整图像大小

System.Drawing.Image imgToResize = null;
Bitmap bmpImage = null;
Graphics grphImage = null;

try
{
    imgToResize = System.Drawing.Image.FromFile ( "image path" );

    bmpImage = new Bitmap ( resizeWidth , resizeheight );
    grphImage = Graphics.FromImage ( ( System.Drawing.Image ) bmpImage );

    grphImage.InterpolationMode = InterpolationMode.HighQualityBicubic;
    grphImage.PixelOffsetMode = PixelOffsetMode.HighQuality;
    grphImage.SmoothingMode = SmoothingMode.AntiAlias;
    grphImage.DrawImage ( imgToResize , 0 , 0, resizeWidth , resizeheight );    

    imgToResize.Dispose();  
    grphImage.Dispose();

    bmpImage.Save ( "save location" );
}

catch ( Exception ex )
{
   // your exception handler
}
finally
{               
    bmpImage.Dispose();
}

您需要调整图像的大小

System.Drawing.Image imgToResize = null;
Bitmap bmpImage = null;
Graphics grphImage = null;

try
{
    imgToResize = System.Drawing.Image.FromFile ( "image path" );

    bmpImage = new Bitmap ( resizeWidth , resizeheight );
    grphImage = Graphics.FromImage ( ( System.Drawing.Image ) bmpImage );

    grphImage.InterpolationMode = InterpolationMode.HighQualityBicubic;
    grphImage.PixelOffsetMode = PixelOffsetMode.HighQuality;
    grphImage.SmoothingMode = SmoothingMode.AntiAlias;
    grphImage.DrawImage ( imgToResize , 0 , 0, resizeWidth , resizeheight );    

    imgToResize.Dispose();  
    grphImage.Dispose();

    bmpImage.Save ( "save location" );
}

catch ( Exception ex )
{
   // your exception handler
}
finally
{               
    bmpImage.Dispose();
}


是否要调整图像的大小(可能会扭曲图像)或裁剪图像(将图像的一部分移到新尺寸之外)?是否要调整图像的大小(可能会扭曲图像)或裁剪图像(将图像的一部分移到新尺寸之外)?