2012-11-05 81 views
0

是否可以按比例縮放圖像而不使用3或4個內置屬性之一(因爲它們不能很好地工作)?Visual Basic圖像縮放

什麼我指的是東西,你可以在Java中這樣做:

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

在Java上線似乎很好地縮放尺寸以符合指定大小的工作。

+2

您的代碼包含VB.NET和VBA。你在找嗎?這裏是VBA的實現:http://stackoverflow.com/questions/2029724/add-an-image-to-word-document-and-scale-it-using-vba –

+0

@RichardMorgan:謝謝我糾正了這一點。 – Kairan

回答

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 
+0

這看起來相當激烈,我不認爲我的技能已經達到了這個水平,但我會放棄它。謝謝 – Kairan

+0

好吧,如果你有任何後續問題,請回到這裏。 – tcarvin

+0

「&HCC0020」是指0xCC0020嗎?這是SRCCOPY常數的值嗎?我不是在開玩笑,我正在尋找微軟無法正確記錄的常量值! – Bitterblue