Visual Basic图像缩放

时间:2012-11-05 14:04:37

标签: image vba vb6 scalability

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

我指的是你可以用Java做的事情:

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

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

1 个答案:

答案 0 :(得分:0)

我有一个UserControl,我用它来完成更好的质量调整。这是它的摘录,希望你能发现它很有用。

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