我需要调整bmp的大小,就像在MS Paint中调整大小一样 - 没有抗锯齿。 任何人都知道如何在c#或vb.net中执行此操作?
答案 0 :(得分:2)
您可以使用Image.GetThumbnailImage
方法。我不知道它抗锯齿。
编辑:因为我最近在一个项目中使用了这个缩略图。但是你只是要求调整大小。这种方法可能无法实现高质量的大尺寸调整。
http://msdn.microsoft.com/en-us/library/system.drawing.image.getthumbnailimage.aspx
答案 1 :(得分:1)
答案 2 :(得分:1)
Paint只关闭图像,不是吗?该页面上的示例包含您需要的工具。
答案 3 :(得分:1)
您可以将图形插值模式设置为最近邻居,然后使用drawimage调整其大小而不进行消除锯齿。 (原谅我的vb :-))
Dim img As Image = Image.FromFile("c:\jpg\1.jpg")
Dim g As Graphics
pic1.Image = New Bitmap(180, 180, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
g = Graphics.FromImage(pic1.Image)
g.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
g.DrawImage(img, 0, 0, pic1.Image.Width, pic1.Image.Height)
答案 4 :(得分:0)
@Robert - 最近,由于品牌重塑和转售,Paint.Net成为了封闭源。但是,旧版本(3.36)仍然是开源的。
答案 5 :(得分:0)
// ********************************************** ScaleBitmap
/// <summary>
/// Scale a bitmap by a scale factor, growing or shrinking
/// both axes, maintaining the aspect ratio
/// </summary>
/// <param name="inputBmp">
/// Bitmap to scale
/// </param>
/// <param name="scale_factor">
/// Factor by which to scale
/// </param>
/// <returns>
/// New bitmap containing the original image, scaled by the
/// scale factor
/// </returns>
/// <citation>
/// A Bitmap Manipulation Class With Support For Format
/// Conversion, Bitmap Retrieval from a URL, Overlays, etc.,
/// Adam Nelson, The Code Project, September 2003.
/// </citation>
private Bitmap ScaleBitmap ( Bitmap bitmap,
float scale_factor )
{
Graphics g = null;
Bitmap new_bitmap = null;
Rectangle rectangle;
int height = ( int ) ( ( float ) bitmap.Size.Height *
scale_factor );
int width = ( int ) ( ( float ) bitmap.Size.Width *
scale_factor );
new_bitmap = new Bitmap ( width,
height,
PixelFormat.Format24bppRgb );
g = Graphics.FromImage ( ( Image ) new_bitmap );
g.InterpolationMode = InterpolationMode.High;
g.ScaleTransform ( scale_factor, scale_factor );
rectangle = new Rectangle ( 0,
0,
bitmap.Size.Width,
bitmap.Size.Height );
g.DrawImage ( bitmap,
rectangle,
rectangle,
GraphicsUnit.Pixel );
g.Dispose ( );
return ( new_bitmap );
}