Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Private Const PS_SOLID = 0 Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As Long) As Long Private Sub Command1_Click() Picture1.AutoRedraw = True Picture1.Scale (0, 0)-(255, 100) Picture1.Line (20, 20)-(80, 80), vbRed End SubPrivate Sub Command2_Click() Dim ret As Long Dim re As Long Dim re1 As Long Picture1.ScaleMode = 3 Picture1.Scale (0, 0)-(255, 100)Picture1.AutoRedraw = True X1 = Int(20 * Picture1.Width / 255 / Screen.TwipsPerPixelX) Y1 = Int(20 * Picture1.Height / 100 / Screen.TwipsPerPixelY) X2 = Int(80 * Picture1.Width / 255 / Screen.TwipsPerPixelX) Y2 = Int(80 * Picture1.Height / 100 / Screen.TwipsPerPixelY) Debug.Print X1 & "/" & Y1 & "/"; X2 & "/" & Y2 re1 = MoveToEx(Picture1.hdc, X1, Y1, 0&) ret = CreatePen(PS_SOLID, 2, &HFFFFFF) re = LineTo(Picture1.hdc, X2, Y2) DeleteObject ret End Sub
1像素=15缇,应该在那里改呢?在lineto函数中吗?
回复patrickkong
我试过了,似乎没有用,你是否用过呢?能说的具体些吗?
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Const PS_SOLID = 0
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As Long) As Long
Private Sub Command1_Click()
Picture1.AutoRedraw = True
Picture1.Scale (0, 0)-(255, 100)
Picture1.Line (20, 20)-(80, 80), vbRed
End SubPrivate Sub Command2_Click()
Dim ret As Long
Dim re As Long
Dim re1 As Long
Picture1.ScaleMode = 3
Picture1.Scale (0, 0)-(255, 100)Picture1.AutoRedraw = True
X1 = Int(20 * Picture1.Width / 255 / Screen.TwipsPerPixelX)
Y1 = Int(20 * Picture1.Height / 100 / Screen.TwipsPerPixelY)
X2 = Int(80 * Picture1.Width / 255 / Screen.TwipsPerPixelX)
Y2 = Int(80 * Picture1.Height / 100 / Screen.TwipsPerPixelY)
Debug.Print X1 & "/" & Y1 & "/"; X2 & "/" & Y2
re1 = MoveToEx(Picture1.hdc, X1, Y1, 0&)
ret = CreatePen(PS_SOLID, 2, &HFFFFFF)
re = LineTo(Picture1.hdc, X2, Y2)
DeleteObject ret
End Sub
可是在我的程序中我没有运行出来,能帮我看看哪里出错了吗?
这是以前用VB Line画的
Form1.picScope.Line ((ny0 - 128) * 10 * Points(i, 0) + 128, i * nx)-((ny1 - 128) * 10 * Points(i + 1, 0) + 128, i * nx + nx)
这是调整之后的
X1 = Int(i * nx * Form1.picScope.Width / 255 / Screen.TwipsPerPixelX)
Y1 = Int(((ny0 - 128) * 10 * Points(i, 0) + 128) * Form1.picScope.Height / 100 / Screen.TwipsPerPixelY)
X2 = Int((i + 1) * nx * Form1.picScope.Width / 255 / Screen.TwipsPerPixelX)
Y2 = Int(((ny1 - 128) * 10 * Points(i + 1, 0) + 128) * Form1.picScope.Height / 100 / Screen.TwipsPerPixelY)
re1 = MoveToEx(Form1.picScope.hdc, Y1, X1, 0&)
re = LineTo(Form1.picScope.hdc, Y2, X2)
好像Y1,Y2都超出了坐标范围。
还有怎么感觉用API画图的效率反而不如VB Line快了呢?
Y1 =
X2 =
Y2 =
怎么写转换代码