(已解决,谢谢netegg)gdi使用中问题
本帖最后由 续缘8003 于 2014-11-3 19:23 编辑摘自本论坛的代码绘制了曲线图,如下代码
现在的问题是如果中间的一段缺数了,如何画出曲线图形
即代码中曲线为1到200,其中50到80缺数(也可能是40到50),如何画出来图形
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
Opt('MustDeclareVars', 1)
Global $hGUI, $hWnd, $hGraphic,$WM_PAINT
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
_Main()
Func _Main()
Local $hBrush, $hAsymPen, $hFormat, $hFamily, $hFont, $tLayout, $hPen
Local $aPoint, $aPoint2, $j = 1
; 创建界面
;$hGUI = GUICreate("Parabola", 400, 300)
;$hWnd = WinGetHandle("Parabola")
$hGUI = GUICreate("", 350, 350)
;GUICreate()
$hWnd = WinGetHandle($hGUI)
GUISetState()
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 8, 2)
_GDIPlus_GraphicsDrawLine($hGraphic, 60, 350, 200, 350, $hPen)
$tLayout = _GDIPlus_RectFCreate(200, 150, 50, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, 'O(0,0)', $hFont, $tLayout, $hFormat, $hBrush)
$tLayout = _GDIPlus_RectFCreate(20, 20, 200, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, '', $hFont, $tLayout, $hFormat, $hBrush)
$tLayout = _GDIPlus_RectFCreate(100, 150, 50, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, '-1', $hFont, $tLayout, $hFormat, $hBrush)
$tLayout = _GDIPlus_RectFCreate(300, 150, 50, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, '1', $hFont, $tLayout, $hFormat, $hBrush)
$hPen = _GDIPlus_PenCreate()
_GDIPlus_GraphicsDrawLine($hGraphic, 0, 150, 400, 150, $hPen)
; _GDIPlus_GraphicsDrawLine($hGraphic, 60, 20, 60, 600, $hPen);60横坐标,600纵坐标
; _GDIPlus_GraphicsDrawLine($hGraphic, 60, 600, 400, 600, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, 200, 0, 200, 300, $hPen)
$hAsymPen = _GDIPlus_PenCreate()
_GDIPlus_PenSetDashStyle($hAsymPen, $GDIP_DASHSTYLEDASH)
_GDIPlus_GraphicsDrawLine($hGraphic, 100, 0, 100, 300, $hAsymPen)
_GDIPlus_GraphicsDrawLine($hGraphic, 300, 0, 300, 300, $hAsymPen)
$aPoint = 200
$aPoint2 = 200
For $i = 0 To 200 Step 1
$aPoint[$j] = $i * 3 + 0
$aPoint[$j] = 150 - Sqrt($i * 5)
$aPoint2[$j] = $i * 3 + 0
$aPoint2[$j] = 150 + Sqrt($i * 5)
$j += 1
Next
_GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint)
_GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint2)
; 循环至用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; 清除资源
_GDIPlus_PenDispose($hPen)
_GDIPlus_PenDispose($hAsymPen)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
EndFunc ;==>_Main
Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
_GDIPlus_GraphicsDrawEllipse ($hGraphic, 130, 100, 140, 70)
Return $GUI_RUNDEFMSG
EndFunc 再顶一下
我的意思就是如何画一条有断点的曲线
不懂……帮顶… 本帖最后由 netegg 于 2014-11-2 19:47 编辑
设置好取样点的范围就行了
另外一种方式,设置有线的地方,笔色为黑色,非范围内的地方,把笔删掉 谢谢 netegg的指导,采用如下语句画线
_GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint)
如果是较少的数据还可以分段取点,数据多了也不固定在某段,很难设置取样点
设置有线的笔为黑色,非范围内的删掉,能否举个例子
我试了多次,画完图后,再原图基础上再往回画图就不行了
请 netegg元老继续指导 不考虑断点的情况下,曲线是连续的吗 本帖最后由 netegg 于 2014-11-2 20:45 编辑
#include <Math.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
Opt('MustDeclareVars', 1)
_Main()
Func _Main()
Local $hGUI, $hWnd, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $hPen, $hPen1
Local $aPoint1,$aPoint2 , $m =1, $j=1, $hAsymPen
; 创建界面
$hGUI = GUICreate("Inverse Secant", 400, 300)
$hWnd = WinGetHandle("Inverse Secant")
GUISetState()
; 绘制字符串
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 8, 2)
$tLayout = _GDIPlus_RectFCreate(200, 150, 50, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, 'O(0,0)', $hFont, $tLayout, $hFormat, $hBrush)
$tLayout = _GDIPlus_RectFCreate(20, 20, 200, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, 'Inverse Secant', $hFont, $tLayout, $hFormat, $hBrush)
$tLayout = _GDIPlus_RectFCreate(244, 150, 20, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, '1', $hFont, $tLayout, $hFormat, $hBrush)
$tLayout = _GDIPlus_RectFCreate(150, 150, 20, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, '-1', $hFont, $tLayout, $hFormat, $hBrush)
$hPen = _GDIPlus_PenCreate()
_GDIPlus_GraphicsDrawLine($hGraphic, 0, 150, 248, 150, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, 252, 150, 400, 150, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, 200, 0, 200, 300, $hPen)
_GDIPlus_GraphicsDrawEllipse($hGraphic, 248, 148, 4, 4)
$aPoint1 = 299
$aPoint2 = 299
For $i = -4 To -1.01 Step 0.01
$aPoint1[$m] = $i * 50 + 200
$aPoint1[$m] = 150 - _ASec($i) * 30
$m += 1
Next
_GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint1)
For $i = 1.01 To 4 Step 0.01
$aPoint2[$j] = $i * 50 + 200
$aPoint2[$j] = 150 - _ASec($i) * 30
$j += 1
Next
_GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint2)
_GDIPlus_GraphicsDrawEllipse($hGraphic, $aPoint1[$m-1] -1, $aPoint1[$m-1]-1, 4, 4)
$hAsymPen = _GDIPlus_PenCreate()
_GDIPlus_PenSetDashStyle($hAsymPen, $GDIP_DASHSTYLEDOT)
_GDIPlus_GraphicsDrawLine($hGraphic, 150, 0, 150, $aPoint1[$m-1]-1, $hAsymPen)
_GDIPlus_GraphicsDrawLine($hGraphic, 150, $aPoint1[$m-1]+3, 150, 300, $hAsymPen)
_GDIPlus_GraphicsDrawLine($hGraphic, 0, ($aPoint1+$aPoint2[$j-1])/2, 400, ($aPoint1+$aPoint2[$j-1])/2, $hAsymPen)
$tLayout = _GDIPlus_RectFCreate(200, ($aPoint1+$aPoint2[$j-1])/2 - 15, 40, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, 'π/2', $hFont, $tLayout, $hFormat, $hBrush)
; 循环至用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; 清除资源
_GDIPlus_PenDispose($hPen)
_GDIPlus_PenDispose($hAsymPen)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
EndFunc ;==>_Main
#include <Math.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
Opt('MustDeclareVars', 1)
_Main()
Func _Main()
Local $hGUI, $hWnd, $hGraphic, $hBrush, $tLayout1, $hFormat, $hFamily, $hFont, $tLayout, $hPen, $hDashPen
Dim $aPoint, $j = 0, $w = 1
; 创建界面
$hGUI = GUICreate("Tangent", 400, 300)
$hWnd = WinGetHandle("Tangent")
GUISetState()
; 绘制字符串
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 8, 2)
$tLayout = _GDIPlus_RectFCreate(200, 150, 20, 20)
_GDIPlus_GraphicsDrawStringEx($hGraphic, 'O', $hFont, $tLayout, $hFormat, $hBrush)
$tLayout = _GDIPlus_RectFCreate(20, 20, 200, 1000)
_GDIPlus_GraphicsDrawStringEx($hGraphic, 'Tangent', $hFont, $tLayout, $hFormat, $hBrush)
$hPen = _GDIPlus_PenCreate()
_GDIPlus_GraphicsDrawLine($hGraphic, 0, 150, 400, 150, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, 200, 0, 200, 300, $hPen)
$hDashPen = _GDIPlus_PenCreate()
_GDIPlus_PenSetDashStyle($hDashPen, $GDIP_DASHSTYLEDOT)
$aPoint = 801
For $i = -8 To 8 Step 0.01
$aPoint[$j] = $i * 50 + 200
$aPoint[$j] = 150 - _Tan($i * $pi) * 50
If $j Then
If $j > 2 Then
Dim $a0 = 150 - $aPoint[$j]
Dim $a1 = 150 - $aPoint[$j - 1]
Dim $a2 = 150 - $aPoint[$j - 2]
If (150 - $a0) * (150 - $a2) < 0 Then
$w += 1
_GDIPlus_GraphicsDrawLine($hGraphic, $aPoint[$j - 1] + 4, 0, $aPoint[$j - 1] + 4, 300, $hDashPen)
$tLayout = _GDIPlus_RectFCreate($aPoint[$j - 1] + 4, 150, 70, 40)
_GDIPlus_GraphicsDrawStringEx($hGraphic, ($w * 2 - 19) & 'π/2', $hFont, $tLayout, $hFormat, $hBrush)
EndIf
EndIf
If $aPoint[$j] * $aPoint[$j - 1] < 0 Then
ReDim $aPoint[$j+1]
$aPoint = $j
_GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint)
$aPoint = 0
ReDim $aPoint
$aPoint = 801
$j = 0
EndIf
EndIf
$j += 1
Next
; 循环至用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; 清除资源
_GDIPlus_PenDispose($hPen)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
EndFunc ;==>_Main
本帖最后由 续缘8003 于 2014-11-2 21:04 编辑
谢谢netegg 元老的耐心讲解,我正在看您的代码,
我用_GDIPlus_GraphicsDrawLine完成了断点的问题,只是曲线中有不连续的地方,很奇怪
再一次谢谢。 本帖最后由 netegg 于 2014-11-2 21:07 编辑
首先创建两个画笔,一个黑色,一个透明,取点的横坐标,在范围内用黑色,不在范围内不画 好的,我在试一试,我的math.au3中没有 _Tan等,不知为何 那是没有,我加的 #include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
Opt('MustDeclareVars', 1)
Global $hGUI, $hWnd, $hGraphic;,$WM_PAINT
;GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
_Main()
Func _Main()
Local $hBrush, $hAsymPen, $hFormat, $hFamily, $hFont, $tLayout, $hPen
Local $aPoint, $aPoint2, $j = 1
; 创建界面
;$hGUI = GUICreate("Parabola", 400, 300)
;$hWnd = WinGetHandle("Parabola")
$hGUI = GUICreate("", 350, 350)
;GUICreate()
$hWnd = WinGetHandle($hGUI)
GUISetState()
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
$aPoint = 200
$aPoint2 = 200
For $i = 0 To 200 Step 1
If Not($i < 10 or $i<20) and Not($i>100 and $i<180) then
$aPoint[$j] = $i * 3 + 0
$aPoint[$j] = 150 - Sqrt($i * 5)
$aPoint2[$j] = $i * 3 + 0
$aPoint2[$j] = 150 + Sqrt($i * 5)
$j += 1
EndIf
Next
_GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint)
_GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint2)
; 循环至用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; 清除资源
_GDIPlus_PenDispose($hPen)
_GDIPlus_PenDispose($hAsymPen)
_GDIPlus_FontDispose($hFont)
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
EndFunc ;==>_Main
#cs
Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
_GDIPlus_GraphicsDrawEllipse ($hGraphic, 130, 100, 140, 70)
Return $GUI_RUNDEFMSG
EndFunc
#ce
谢谢netegg元老,您的热心是大家的榜样
上图中需要表达的意思是1到200曲线是连续的
但我想人为让150到160之间缺数,就是用白色的透明画笔画出来,
其他的数据依旧用黑色的画笔画出,看着好像曲线缺了一部分,
看了您的代码,我再多试试 If $i >150 and $i<160 then
创建个白色的笔,一样画
页:
[1]
2