图片转换缩小问题 大家帮忙看看【已解决】
本帖最后由 261869247 于 2010-7-26 16:47 编辑这个是原图片
这个是效果
大家帮忙修改下代码 点保存的时候 生成另外一张和窗口显示大小一样的图片保存到桌面
也就是保存后的图片大小为105*105像素#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\桌面\图片上传.kxf
$Form1_1 = GUICreate("Form1", 365, 184, 375, 174)
$Group1 = GUICtrlCreateGroup("上传头像注意事项", 144, 8, 217, 105)
$Label1 = GUICtrlCreateLabel("第一行", 152, 24, 40, 17)
$Label2 = GUICtrlCreateLabel("第二行", 152, 40, 40, 17)
$Label3 = GUICtrlCreateLabel("第三行", 152, 56, 40, 17)
$Label4 = GUICtrlCreateLabel("第四行", 152, 72, 40, 17)
$Label5 = GUICtrlCreateLabel("第五行", 152, 88, 40, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Pic1 = GUICtrlCreatePic("1.jpg", 16, 8, 105, 105)
$Button1 = GUICtrlCreateButton("打开图片文件", 40, 128, 105, 41)
$Button2 = GUICtrlCreateButton("保存", 192, 128, 105, 41)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$touxiang = FileOpenDialog("请选择你的头像图片文件", "", "(*.gif;*.jpg;*.bmp)")
GUICtrlSetImage($Pic1, $touxiang)
EndSwitch
WEnd
#include <GDIPlus.au3>
Local $touxiang, $msg, $w = 105, $h = 105
$Form1_1 = GUICreate('Form1', 365, 184)
$Group1 = GUICtrlCreateGroup('上传头像注意事项', 144, 8, 217, 105)
$Label1 = GUICtrlCreateLabel('第一行', 152, 24, 40, 17)
$Label2 = GUICtrlCreateLabel('第二行', 152, 40, 40, 17)
$Label3 = GUICtrlCreateLabel('第三行', 152, 56, 40, 17)
$Label4 = GUICtrlCreateLabel('第四行', 152, 72, 40, 17)
$Label5 = GUICtrlCreateLabel('第五行', 152, 88, 40, 17)
GUICtrlCreateGroup('', -99, -99, 1, 1)
$Pic1 = GUICtrlCreatePic('', 16, 8, $w, $h)
$Button1 = GUICtrlCreateButton('打开图片文件', 40, 128, 105, 41)
$Button2 = GUICtrlCreateButton('保存', 192, 128, 105, 41)
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Button1
$touxiang = FileOpenDialog('请选择你的头像图片文件', '', '(*.gif;*.jpg;*.bmp)')
GUICtrlSetImage($Pic1, $touxiang)
Case $Button2
$filename = StringRegExp($touxiang, '.+\\(.+)\.([^\.]+)', 3)
If @error Then ContinueLoop MsgBox(48, '错误', '还未选择文件')
$O_pic = @DesktopDir & '\' & $filename & '_new.' & $filename
If FileExists($O_pic) Then $msg = MsgBox(1 + 48, '问题', $O_pic & ' 已存在,重建时需先删除原文件,是否确定?')
If $msg = 2 Then ContinueLoop
FileDelete($O_pic)
$hWnd = _WinAPI_GetDesktopWindow()
$hDC = _WinAPI_GetDC($hWnd)
$hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
_WinAPI_ReleaseDC($hWnd, $hDC)
_GDIPlus_Startup()
$hOut = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
$hIn = _GDIPlus_ImageLoadFromFile($touxiang)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hOut)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hIn, 0, 0, $w, $h)
$CLSID = _GDIPlus_EncodersGetCLSID($filename)
_GDIPlus_ImageSaveToFileEx($hOut, $O_pic, $CLSID)
_GDIPlus_ImageDispose($hOut)
_GDIPlus_ImageDispose($hIn)
_GDIPlus_GraphicsDispose($hGraphic)
_WinAPI_DeleteObject($hBMP)
_GDIPlus_Shutdown()
If FileExists($O_pic) Then MsgBox(64, '完成', '已生成新图片:' & $O_pic)
EndSwitch
WEnd 测试了楼上的代码,不错,好用! 代码收下了... 哈哈 afan 老大怎么来了 是被我的图片吸引来的吧 哈哈哈
谢谢啊 小小的功能 代码都要这么长 难怪我琢磨不出来 哈哈 受教了 非常感谢AFAN斑竹``` 这个头像 赞,哈哈
笑死我啦
页:
[1]