2016-07-31 74 views
-1

我已經試過Resizing an Image without losing any quality沒有運氣鐵血質量。VB.NET - 使用的DrawImage用的ImageList

他們是64×64巴紐的(調整大小的應用程式,以20×20)與下8位色彩模式(32位色彩模式中,應用程序中設置)在Photoshop製作一個透明背景。 (當我將它設置在Photoshop中爲32位,這不會讓我保存爲.png所以我一直是在8)

This is what it looks like

(HD Image + Raw Icon Files)

(它是一種自定義的TabControl)

Sub New() 

    SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint Or ControlStyles.SupportsTransparentBackColor, True) 
    DoubleBuffered = True 
    SizeMode = TabSizeMode.Fixed 
    ItemSize = New Size(30, 32) 

End Sub 

Protected Overrides Sub CreateHandle() 

    MyBase.CreateHandle() 
    Alignment = TabAlignment.Left 
    ItemSize = New Size(30, 32) 

End Sub 

Protected Overrides Sub OnPaint(e As PaintEventArgs) 

    'Variables; 
    Dim bmp As New Bitmap(Width, Height) 
    Dim gfx As Graphics = Graphics.FromImage(bmp) 
    Dim n_bounds As New Rectangle(New Point(e.ClipRectangle.X + 2, e.ClipRectangle.Y + 2), New Size(e.ClipRectangle.Width - 6, e.ClipRectangle.Height - 6)) 

    'Set the Graphics Rendering Quality to Max; (Doesnt seem to do crap) 
    gfx.SmoothingMode = SmoothingMode.HighQuality 
    gfx.InterpolationMode = InterpolationMode.HighQualityBicubic 
    gfx.PixelOffsetMode = PixelOffsetMode.HighQuality 
    gfx.CompositingQuality = CompositingQuality.HighQuality 
    e.Graphics.SmoothingMode = SmoothingMode.HighQuality 
    e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic 
    e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality 
    e.Graphics.CompositingQuality = CompositingQuality.HighQuality 

    gfx.Clear(Color.FromArgb(148, 163, 177)) 

    'For Each Tab; 
    For i = 0 To TabCount - 1 

     'Get the Tab's Bounds; 
     Dim rect As Rectangle = GetTabRect(i) 

     'If it's the Selected Tab Design it with a Gradient - otherwise just use a Solid Color; 
     If i = SelectedIndex Then 
      gfx.FillRectangle(New Drawing2D.LinearGradientBrush(New PointF(rect.X, rect.Y + 30), New PointF(rect.X + 30, rect.Y), Color.FromArgb(147, 255, 155), Color.FromArgb(148, 163, 177)), rect) 
     Else 
      gfx.FillRectangle(New SolidBrush(Color.FromArgb(141, 155, 169)), rect) 
     End If 

     'Draw the Icon's; 
     If TabPages(i).ImageIndex >= 0 Then 
      Dim img As Image = ImageList.Images(TabPages(i).ImageIndex) 
      Dim x As Single = (rect.X + img.Width) - 30/2 
      Dim y As Single = (rect.Y + img.Height) - 30/2 
      gfx.DrawImage(img.Clone, x, y) 
     End If 

    Next 

    'Draw the Icon and Icon's Background and Selected Icon's Background; 
    e.Graphics.DrawImage(bmp.Clone, 0, 0) 
    gfx.Dispose() : bmp.Dispose() 

    'Draw; 
    MyBase.OnPaint(e) 

End Sub 

回答

0

找到罪魁禍首,似乎實際上是完全因爲ImageList中的 - 顯然,這是默認的行爲,我可以修復它是由剛剛導入圖像作爲資源和使用自定義函數來獲取其中的圖標應該是唯一的辦法顯示在上每個選項卡,然後使用的DrawImage。

質量是100%銳利但不「太鋒利」