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 ?
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
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.
@Robert - Paint.Net recently went closed source because of rebranding and reselling. However, the older versions (3.36) are still open source.
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)
// ********************************************** 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 );
}