找回密码
 加入
搜索
查看: 3516|回复: 7

[图形处理] 图片转换缩小问题 大家帮忙看看【已解决】

  [复制链接]
发表于 2010-7-26 09:57:28 | 显示全部楼层 |阅读模式
本帖最后由 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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-7-26 13:57:17 | 显示全部楼层
#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[0] & '_new.' & $filename[1]
                        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[1])
                        _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
发表于 2010-7-26 14:34:44 | 显示全部楼层
测试了楼上的代码,不错,好用!
发表于 2010-7-26 15:19:03 | 显示全部楼层
代码收下了...
 楼主| 发表于 2010-7-26 16:43:04 | 显示全部楼层
哈哈 afan 老大怎么来了 是被我的图片吸引来的吧 哈哈哈
谢谢啊
 楼主| 发表于 2010-7-26 16:46:52 | 显示全部楼层
小小的功能 代码都要这么长 难怪我琢磨不出来 哈哈 受教了
发表于 2010-11-2 21:20:22 | 显示全部楼层
非常感谢AFAN斑竹```
发表于 2012-5-16 14:00:20 | 显示全部楼层
这个头像 赞,哈哈
笑死我啦
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-18 04:18 , Processed in 0.081220 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表