2009-12-06 45 views
3

我需要調整一個像MS Paint中的調整大小那樣的bmp - 這是沒有反鋸齒的。 任何人都知道如何在c#或vb.net中做到這一點?調整像MS Paint中的位圖

+1

從WPF的新功能通常比老System.Drawing中的人更快,更好。檢查出http://stackoverflow.com/questions/754168/how-to-serve-high-resolution-imagery-in-a-low-resolution-form-using-c – 2009-12-06 19:44:58

回答

1

從MSDN How to: Copy Images

油漆只是將圖像切掉,不是嗎?該頁面上的示例提供了所需的工具。

0

@Robert - Paint.Net最近因爲品牌重塑和轉售而關閉了源代碼。然而,舊版本(3.36)仍然是開源的。

+0

@Moshe,這是更好地表述爲評論根據我的回答,並不是OP的問題的另一個答案。 – 2009-12-06 07:16:10

+2

他需要50個代表。能夠寫評論... – Jan 2009-12-06 19:52:52

1

您可以將圖形插值模式設置爲最近的鄰居,然後使用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) 
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

你想要InterpolationMode.NearestNeighbor - 不是InterpolationMode.High。 – BrainSlugs83 2013-12-18 22:58:23