像在MS Paint中一样调整位图大小

我需要像在MS Paint中resize一样调整bmp的大小 – 这是没有抗锯齿的。 任何人都知道如何在c#或vb.net中执行此操作?

您可以使用Image.GetThumbnailImage方法。 我不知道它抗锯齿。

编辑 :因为我最近在一个项目中使用了这个缩略图。 但是你只是要求resize。 此方法可能无法获得高质量的大尺寸调整。

http://msdn.microsoft.com/en-us/library/system.drawing.image.getthumbnailimage.aspx

请参阅: 使用抗锯齿function在.Net中调整图像大小

如何:从MSDN 复制图像 。

油漆只是将图像切掉,不是吗? 该页面上的示例包含您需要的工具。

您可以将图形插值模式设置为最近邻居,然后使用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) 

@Robert – Paint.Net最近由于品牌重塑和转售而成为封闭源。 但是,旧版本(3.36)仍然是开源的。

  // ********************************************** ScaleBitmap ///  /// Scale a bitmap by a scale factor, growing or shrinking /// both axes, maintaining the aspect ratio ///  ///  /// Bitmap to scale ///  ///  /// Factor by which to scale ///  ///  /// New bitmap containing the original image, scaled by the /// scale factor ///  ///  /// A Bitmap Manipulation Class With Support For Format /// Conversion, Bitmap Retrieval from a URL, Overlays, etc., /// Adam Nelson, The Code Project, September 2003. ///  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 ); }