2014-02-18 246 views
2

我在圖像框中使用此代碼在軌跡欄上縮放圖像。圖像縮放像素化

Private Sub tbrZoomLevel_Scroll(sender As System.Object, e As System.EventArgs) Handles tbrZoomLevel.Scroll 
    With pbImage 
     .SuspendLayout() 
     .Width = actualSize.Width * tbrZoomLevel.Value 
     .Height = actualSize.Height * tbrZoomLevel.Value 
     .ResumeLayout() 
    End With 
End Sub 

pbImage是一個PictureBox控件,sizemode作爲縮放。 actualSize是pbImage中的原始圖像大小。

當我放大時,我得到沒有像素化的圖像。但我希望它完全像素化並顯示縮放時的MS Paint中顯示的圖像。任何幫助表示讚賞。 VB.Net代碼,C#代碼或任何算法都是受歡迎的。

回答

3

在你的PictureBox漆:

Private Sub PictureBox1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint 

    e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor 
    'Draw the image 
End Sub 

編輯:試試這個

Private Sub PictureBox1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint 
    Dim srcRect As RectangleF = New Rectangle(0, 0, PictureBox1.Width/8, PictureBox1.Height/8) 
    Dim dstRect As RectangleF = New RectangleF(0, 0, PictureBox1.Width, PictureBox1.Height) 

    e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor 
    e.Graphics.DrawImage(pctBoxImage, dstRect, srcRect, GraphicsUnit.Pixel) 
End Sub 

pctBoxImagebitmap這將是800% zoomed

Private Sub PictureBox1_Paint(sender As System.Object, e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint 
    e.Graphics.ScaleTransform(8, 8) 
    e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor 
    e.Graphics.DrawImage(pctBoxImage, 0, 0) 
End Sub 

0,0是位圖上左上角位置的座標

valter

+0

我想讓圖像在縮放時與縮放時的MS繪製相同時正確顯示其像素。插值與此相反。在MS油漆中拍照,放大uptu 600或800%,你會看到像素變得更大。我想要相同的行爲。 –

+0

@Sarvesh完全按照你的需要。你會看到像素。看我的編輯 –