2009-12-06 7 views
3

J'ai besoin de redimensionner un bmp comme le redimensionne fonctionne dans MS Paint - c'est-à-dire sans antialiasing. Quelqu'un sait comment faire cela dans C# ou vb.net?Redimensionner bitmap comme dans MS Paint

+1

Les nouvelles fonctions de WPF sont généralement plus rapides et mieux que les anciens System.Drawing. Découvrez http://stackoverflow.com/questions/754168/how-to-serve-high-resolution-imagery-in-a-low-resolution-form-using-c –

Répondre

1

How to: Copy Images de MSDN.

La peinture coupe juste l'image, n'est-ce pas? Les exemples sur cette page ont les outils pour ce dont vous avez besoin.

0

@Robert - Paint.Net est récemment devenu une source fermée en raison du changement de marque et de la revente. Cependant, les anciennes versions (3.36) sont toujours open source.

+0

@Moshe, ceci est mieux indiqué comme commentaire sous ma réponse, pas comme une autre réponse à la question du PO. –

+2

Il a besoin de 50 rep. pour pouvoir écrire des commentaires ... – Jan

1

Vous pouvez définir le mode d'interpolation graphique sur le plus proche voisin, puis utiliser drawimage pour le redimensionner sans anticrénelage. (Pardonnez mon 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
// ********************************************** 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

Vous voulez InterpolationMode.NearestNeighbor - pas InterpolationMode.High. – BrainSlugs83