Resize bitmap like in MS Paint

后端 未结 6 1612
北恋
北恋 2021-01-20 12:23

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 ?

相关标签:
6条回答
  • 2021-01-20 12:34

    Please see: Image resizing in .Net with Antialiasing

    0 讨论(0)
  • 2021-01-20 12:40

    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.

    0 讨论(0)
  • 2021-01-20 12:45

    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

    0 讨论(0)
  • 2021-01-20 12:55

    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)
    
    0 讨论(0)
  • 2021-01-20 12:57
        // ********************************************** 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 );
            }
    
    0 讨论(0)
  • 2021-01-20 12:58

    @Robert - Paint.Net recently went closed source because of rebranding and reselling. However, the older versions (3.36) are still open source.

    0 讨论(0)
提交回复
热议问题