0

是否可以在没有 3 或 4 个内置属性之一的情况下在 VB 中按比例缩放图像(因为它们不能很好地工作)?

我指的是你可以在 Java 中做这样的事情:

Image newimg = img.getScaledInstance(230, 310,  java.awt.Image.SCALE_SMOOTH);  

在 Java 中,上述行似乎可以很好地缩放尺寸以适应指定的尺寸。

4

1 回答 1

0

我有一个用户控件,我用它来完成更好的质量调整。这是其中的摘录,希望对您有用。

Private Const STRETCH_ANDSCANS = 1
Private Const STRETCH_DELETESCANS = 3
Private Const STRETCH_HALFTONE = 4
Private Const STRETCH_ORSCANS = 2
Private Const SRCCOPY = &HCC0020

Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc As Long, _
                                                   ByVal x As Long, _
                                                   ByVal y As Long, _
                                                   ByVal nWidth As Long, _
                                                   ByVal nHeight As Long, _
                                                   ByVal hSrcDC As Long, _
                                                   ByVal xSrc As Long, _
                                                   ByVal ySrc As Long, _
                                                   ByVal nSrcWidth As Long, _
                                                   ByVal nSrcHeight As Long, _
                                                   ByVal dwRop As Long) _
                                                   As Long

Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, _
                                                      ByVal nStretchMode As Long) _
                                                      As Long

它是这样称呼的:

Private Sub UserControl_Paint()

   Dim lSave As Long

   'set the stretchblit mode (saving the previous value)
   lSave = SetStretchBltMode(UserControl.hdc, STRETCH_HALFTONE)

   'perform blit
   Call StretchBlt(UserControl.hdc, 0, 0, UserControl.ScaleWidth, _
                     UserControl.ScaleHeight, picBuffer.hdc, 0, 0, _
                     picBuffer.ScaleWidth, picBuffer.ScaleHeight, SRCCOPY)

   'restore previous mode
   Call SetStretchBltMode(UserControl.hdc, lSave)

End Sub
于 2012-11-07T13:10:32.400 回答