【已解决】JPG图片显示效果和显示坐标的问题?
本帖最后由 newuser 于 2014-11-18 17:17 编辑脚本运行后,图片加载的效果不好?问题来回切换后,图片切换的效果不好?(图片不一样大,想在一个固定区域显示大小不一的图片,不想一个个都给处理成大小一致的)#cs
完成于20141111
1、增加了’参考提示‘
2、了解了题库中’给定答案与用户的选择一致性‘如何用 Bitand()和if语句进行判读
下一阶段任务:
1、给试题添加图片
感谢:
地平线
lanfengc
#ce
#NoTrayIcon
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#Include <Misc.au3>
If _singleton(@scriptname,1)=0 Then
MsgBox(0,"请注意","目前有脚本程序正在运行")
Exit
EndIf
;强制脚本只执行一个设计实例
If Not FileExists(@ScriptDir&"\考试题.ini") Then
MsgBox(0,"请注意","考试题库不存在")
Exit
EndIf
;判断考试题库是否存在
Global $his
;$his一定要设置为“全局变量”,从该字段读题号
GUICreate("考驾照自测题系统",800,600,-1,-1,BitOR($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX))
$his=IniRead(@ScriptDir&"\考试题.ini","His","Num","x");考试从第1题开始
$question=IniRead(@ScriptDir&"\考试题.ini",$his,"问题","x")
$sela=IniRead(@ScriptDir&"\考试题.ini",$his,"SelectA","x")
$selb=IniRead(@ScriptDir&"\考试题.ini",$his,"SelectB","x")
$selc=IniRead(@ScriptDir&"\考试题.ini",$his,"SelectC","x")
$seld=IniRead(@ScriptDir&"\考试题.ini",$his,"SelectD","x")
$selimage=IniRead(@ScriptDir&"\考试题.ini",$his,"ImagePath","x")
;$selimage=IniRead(@ScriptDir"\考试题.ini",$his,"ImagePath","x")
;error:"\考试题.ini"前竟然落了一个 &,找了半天才看到
;error:语法错误,原因是$his前多写了个 ,
;以上执行“将问题和选择从考试题库ini文件中读出来存储在指定的变量中
$key="x";答案变量初始值
$note="x";提示变量初始值
$GUInum=GUICtrlCreateLabel($his,30,40,55,20);自动创建窗口中“题号”的位置
$GUIque=GUICtrlCreateLabel($question,87,40,700,80);自动创建窗口中“问题”的位置
$GUIa=GUICtrlCreateRadio($sela,40,80,700,50,$BS_MULTILINE);以下是4个选择项建立
$GUIb = GUICtrlCreateRadio($selb,40,130,700,50,$BS_MULTILINE)
$GUIc = GUICtrlCreateRadio($selc,40,180,700,50,$BS_MULTILINE)
$GUId = GUICtrlCreateRadio($seld,40,230,700,50,$BS_MULTILINE)
$GUIpic=GUICtrlCreatePic($selimage,350,100,300,194)
;GUICtrlSetData($GUIpic,$selimage)
;把上面读到变量里的内容写在“窗口指定控件位置上”
$GUIsub=GUICtrlCreateButton("提交答案",40,330,100,40)
GUICtrlCreateLabel("参考答案:",50,400)
$GUIkey=GUICtrlCreateLabel($key,120,395,60,20)
GUICtrlCreateLabel("参考提示:",50,430)
$GUInote=GUICtrlCreateLabel($note,120,428,600,80)
;GUICtrlCreateLabel("已自动加载"&@CRLF&"上次答题进度",390,405,100,30,0x01,$WS_EX_CLIENTEDGE)
$GUItab1=GUICtrlCreateLabel("跳转到第",510,330,70,25)
$GUIinput=GUICtrlCreateInput($his,585,330,50,25)
$GUItab2=GUICtrlCreateLabel("题",640,330,20,25)
$GUIgo=GUICtrlCreateButton("Go",665,330,30,30)
$GUIbefore = GUICtrlCreateButton("<<-- 上一题",180,330,100,40)
$GUInext = GUICtrlCreateButton("下一题 -->>",320,330,100,40)
GUICtrlSetFont($GUInum,13)
GUICtrlSetFont($GUIque,13)
GUICtrlSetFont($GUIa,13)
GUICtrlSetFont($GUIb,13)
GUICtrlSetFont($GUIc,13)
GUICtrlSetFont($GUId,13)
GUICtrlSetFont($GUIkey,15)
GUICtrlSetFont($GUItab1,13)
GUICtrlSetFont($GUItab2,13)
GUICtrlSetFont($GUInote,11)
;为窗口设置界面
GUISetState(@SW_SHOW)
While 1
$msg=GUIGetMsg()
Select
Case $msg=$GUIsub
$i=IniRead(@ScriptDir&"\考试题.ini",GUICtrlRead($GUInum),"Key","x")
GUICtrlSetData($GUIkey,$i)
;从考试题库中读取正确答案并设置在提示答案处
;变量 $i 是为了在下面 _YN()函数中对用户的选择进行判断,否则也不用在此建立,就像下面的“答案”提示那样
GUICtrlSetData($GUInote,IniRead(@ScriptDir&'\考试题.ini',$his,"提示","×"))
;$tishi=IniRead(@ScriptDir&"考试题.ini",GUICtrlRead($GUInum),"提示","x")
;GUICtrlSetData($GUInote,$tishi)
;question1:考试题库中的关键字”提示“ 内容过多,多行显示,琢磨怎么通过 iniread()函数把它读取呢?
; 其实,在“记事本”中把“自动换行”功能关闭,再多的内容也给它弄成一行
;question2:在脚本中只显示“一行提示内容”?把显示内容的控件高度增加就OK了,哎!
_YN()
Case $msg=$GUInext
$his=$his+1
GUICtrlSetData($GUIkey,$key)
GUICtrlSetData($GUInote,$note)
GUICtrlSetBkColor($GUIkey,-1);去除“醒目”的背景色
_GUIset()
Case $msg=$GUIbefore
$his=$his-1
GUICtrlSetData($GUIkey,$key)
GUICtrlSetData($GUInote,$note)
GUICtrlSetBkColor($GUIkey,-1)
;question:一直减下去,会出负数,不妥?141111
If$his < 1 Then
$his=1
MsgBox(0,"请注意","目前已经回到第1题")
endif
_GUIset()
Case $msg=$GUIgo
$his=GUICtrlRead($GUIinput)
_GUIset()
Case $msg=$GUI_EVENT_CLOSE
IniWrite(@ScriptDir&"\考试题.ini","His","Num",$his);记忆用户上次答题的位置
ExitLoop
EndSelect
WEnd
GUIDelete()
Func _YN()
GUICtrlSetBkColor($GUIkey,-1);在提示答案处设置背景颜色
$a = BitAnd(GUICtrlRead($GUIa),$GUI_CHECKED)
$b = BitAnd(GUICtrlRead($GUIb),$GUI_CHECKED)
$c = BitAnd(GUICtrlRead($GUIc),$GUI_CHECKED)
$d = BitAnd(GUICtrlRead($GUId),$GUI_CHECKED)
;以上是判读哪个答案被选中了
If $i = "A" And $a <> 1 Then;如果题库给定答案与用户的选择不一致,则在答案提示处设置醒目颜色给以警示
GUICtrlSetBkColor($GUIkey,0xFF1E1E)
ElseIf $i = "B" And $b <> 1 Then
GUICtrlSetBkColor($GUIkey,0xFF1E1E)
ElseIf $i = "C" And $c <> 1 Then
GUICtrlSetBkColor($GUIkey,0xFF1E1E)
ElseIf $i = "D" And $d <> 1 Then
GUICtrlSetBkColor($GUIkey,0xFF1E1E)
EndIf
EndFunc ;==>_YN
Func _GUIset()
GUICtrlSetData($GUInum,$his);默认题号是 $his 的最初设置值
GUICtrlSetData($GUIque,IniRead(@ScriptDir&'\考试题.ini',$his,"问题","×"))
GUICtrlSetData($GUIa,IniRead(@ScriptDir&'\考试题.ini',$his,"SelectA","×"))
GUICtrlSetData($GUIb,IniRead(@ScriptDir&'\考试题.ini',$his,"SelectB","×"))
GUICtrlSetData($GUIc,IniRead(@ScriptDir&'\考试题.ini',$his,"SelectC","×"))
GUICtrlSetData($GUId,IniRead(@ScriptDir&'\考试题.ini',$his,"SelectD","×"))
$GUIpiccheck=IniRead(@ScriptDir&"\考试题.ini",$his,"ImagePath","")
If $GUIpiccheck="" Then
GUICtrlSetState($GUIpic,$GUI_HIDE)
Else
$GUIpic=GUICtrlCreatePic($GUIpiccheck,350,100,300,194)
;GUICtrlSetImage($GUIpic,$GUIpiccheck)
EndIf
;设置进入界面显示哪道题
;此处不需照猫画虎:GUICtrlSetData($GUInote,IniRead(@ScriptDir&'\考试题.ini',$his,"提示","×"))
EndFunc ;==>_GUIset
回复 1# newuser
等... 不明白,固定区域显示,大小不一样,是什么意思 楼主提的问题太不明确了 #include <GDIPlus.au3>
Opt('GUIOnEventMode', 1)
Dim $w_picctrl = 498, $h_picctrl = 298
$Form1 = GUICreate('居中显示图像例子 - afan', 600, 430, -1, -1, -1, 0x00000010)
GUISetOnEvent(-3, '_Exit')
GUISetOnEvent(-13, 'Show')
GUICtrlCreateGraphic(50, 50, 500, 300)
GUICtrlSetGraphic(-1, 10, 0, 0,500,300)
$ts = GUICtrlCreateLabel('请拖拽任意图片至本框中', 51, 51,498,298, 0x01 + 0x0200)
GUICtrlSetState(-1, 8)
$pic = GUICtrlCreatePic('', 51, 51,500,300)
GUICtrlCreateLabel('图片文件路径:', 50, 355, 90, 17)
$ts_File = GUICtrlCreateLabel('', 140, 355, 400, 17)
GUICtrlCreateLabel('图片原始尺寸:', 50, 370, 90, 17)
$ts_size = GUICtrlCreateLabel('', 140, 370, 200, 17)
GUICtrlCreateLabel('格式(后缀名):', 50, 385, 90, 17)
$ts_hzm = GUICtrlCreateLabel('', 140, 385, 90, 17)
GUISetState()
WinSetOnTop($Form1, '', 1)
While 1
Sleep(10)
WEnd
Func _Exit()
GUIDelete()
Exit
EndFunc ;==>_Exit
Func Show()
Local $imgfile = @GUI_DragFile
GUICtrlSetData($ts_hzm, StringRegExpReplace($imgfile, '.+\\.+\.', ''))
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($imgfile)
$w_img = _GDIPlus_ImageGetWidth($hImage)
$h_img = _GDIPlus_ImageGetHeight($hImage)
If $w_img * $h_img = 0 Then
_GDIPlus_Shutdown()
Return MsgBox(48, @error, '非图片格式', '', $Form1)
EndIf
GUICtrlSetData($ts, '')
GUICtrlSetData($ts_size, $w_img & ' x ' & $h_img)
GUICtrlSetData($ts_File, $imgfile)
GUICtrlSetData($ts_hzm, StringRegExpReplace($imgfile, '.+\\.+\.', ''))
Local $kgb = $h_picctrl / $w_picctrl
Local $kgb1 = $h_img / $w_img
Local $x_py = 0, $y_py = 0, $hBMP, $hObject
If $w_img > $w_picctrl Or $h_img > $h_picctrl Then
If $kgb1 > $kgb Then
$h_img = $h_picctrl
$w_img = Round(1 / $kgb1 * $h_img)
$x_py = ($w_picctrl - $w_img) / 2
Else
$w_img = $w_picctrl
$h_img = Round($kgb1 * $w_img)
$y_py = ($h_picctrl - $h_img) / 2
EndIf
Else
$x_py = ($w_picctrl - $w_img) / 2
$y_py = ($h_picctrl - $h_img) / 2
EndIf
$hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hObject = GUICtrlSendMsg($pic, 0x0172, 0, $hBMP)
GUICtrlSetPos($pic, 51 + $x_py - 1, 51 + $y_py - 1, $w_img, $h_img)
GUICtrlSetPos($pic, 51 + $x_py, 51 + $y_py)
_WinAPI_DeleteObject($hObject)
_GDIPlus_ImageDispose($hImage)
_WinAPI_DeleteObject($hBMP)
_GDIPlus_Shutdown()
EndFunc ;==>Show看看对你有用不?非原创,出处已忘! 本帖最后由 newuser 于 2014-11-18 16:33 编辑
回复 3# netegg
很多图片大小不一样,我想在固定区域完整加载它们(例子中只是加载了2个JPG图片,高度和宽度设置不合适,图片会显示不全!调来调去很麻烦,后面的题还有很多图片)!而且,例子加载的图片显示效果有问题,不知道怎么回事?
老大,麻烦帮助看一下,增加到10道题,后面几题都有图片,纳闷的是加载的图片怎么还串了呢(第9题加载的图片和第10题加载的图片颠倒了)? 回复 5# ap112
谢谢,学习一下! 回复 1# newuser
图片加载迷糊了!哎,继续等待中... 回复 1# newuser
明白了,原来是窗口各个控件的坐标没弄好,造成了加载的图片被覆盖,导致了图片显示问题?还以为代码哪个地方出错了呢!
页:
[1]