3

I need to resize a bmp like the resize works in MS Paint - that is with no antialiasing . Anyone know how to do this in c# or vb.net ?

dwwater
  • 41
  • 1
  • 3
  • 1
    The new functions from WPF are generally faster and better than the old System.Drawing ones. Check out http://stackoverflow.com/questions/754168/how-to-serve-high-resolution-imagery-in-a-low-resolution-form-using-c – Mikael Svenson Dec 06 '09 at 19:44

5 Answers5

4

You can set the graphics interpolation mode to nearest neighbor and then use drawimage to resize it without anti-aliasing. (pardon my 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)
xpda
  • 15,585
  • 8
  • 51
  • 82
2

You can use the Image.GetThumbnailImage method. I am not aware of it antialiasing.

EDIT: I was thinking of thumbnail images since I recently used this in a project. But you are just asking for resizing in general. This method may not result in good quality large resizing.

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

David
  • 12,451
  • 1
  • 22
  • 17
1

Please see: Image resizing in .Net with Antialiasing

Community
  • 1
  • 1
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
1

How to: Copy Images from MSDN.

Paint just chops the image off, doesn't it? The examples on that page have the tools for what you need.

UncleO
  • 8,299
  • 21
  • 29
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 );
        }
Gus
  • 1,383
  • 2
  • 12
  • 23