找回密码
 加入
搜索
查看: 4565|回复: 6

[AU3基础] [已解決]怎样能做到输出JPG文件为800x600呢

  [复制链接]
发表于 2014-11-6 19:53:03 | 显示全部楼层 |阅读模式
本帖最后由 abcd1258 于 2014-11-14 19:44 编辑

请教一下大家一个问题,要怎么才能输出JPG文件为800x600大小呢?
在此先谢谢大家。
#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

GUICreate('123.JPG', 623, 445)
DirCreate(@ScriptDir & "\456")
Local $Button1 = GUICtrlCreateButton('插入',144, 272, 150, 30)
Local $Pic1 = GUICtrlCreatePic('', 128, 24, 337, 185)
Local $Button2 = GUICtrlCreateButton('保存', 336, 272, 150, 30)
Local $sPathPic
GUISetState()
While 1
        Switch GUIGetMsg()
                Case -3
                        Exit
                Case $Button1
                        $sPathPic = FileOpenDialog('浏览照片', @MyDocumentsDir & '\', '图像文件 (*.jpg;*.bmp)', 1)
                        GUICtrlSetPos($Pic1, 128, 24, 337, 185)
                        GUICtrlSetImage($Pic1, $sPathPic)
                Case $Button2
                        If FileCopy($sPathPic, @ScriptDir & "\456\12.jpg", 1) Then
                                                        Else
                                                EndIf
                                        Exit
        EndSwitch
WEnd
输出图片
 楼主| 发表于 2014-11-6 20:06:08 | 显示全部楼层
想加上这段,不知道怎么加。
http://www.autoitx.com/forum.php?mod=viewthread&tid=44623
发表于 2014-11-7 11:59:32 | 显示全部楼层
FileCopy($sPathPic, @ScriptDir & "\456\12.jpg", 1)
换成
_PIC2JPG($sPathPic, @ScriptDir & "\456\12.jpg",  800, 600)
 楼主| 发表于 2014-11-7 18:58:56 | 显示全部楼层
回复 3# seniors
#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

GUICreate('123.JPG', 623, 445)
DirCreate(@ScriptDir & "\456")
Local $Button1 = GUICtrlCreateButton('插入',144, 272, 150, 30)
Local $Pic1 = GUICtrlCreatePic('', 128, 24, 337, 185)
Local $Button2 = GUICtrlCreateButton('保存', 336, 272, 150, 30)
Local $sPathPic
GUISetState()
While 1
        Switch GUIGetMsg()
                Case -3
                        Exit
                Case $Button1
                        $sPathPic = FileOpenDialog('浏览照片', @MyDocumentsDir & '\', '图像文件 (*.jpg;*.bmp)', 1)
                        GUICtrlSetPos($Pic1, 128, 24, 337, 185)
                        GUICtrlSetImage($Pic1, $sPathPic)
                                Case $Button2
                        If _PIC2JPG($sPathPic, @ScriptDir & "\456\12.jpg",  800, 600) Then
                                                        Else
                                                EndIf
                                        Exit
        EndSwitch
WEnd

Func _PIC2JPG($sFile, $sFile_new, $new_W, $new_H, $IQUALITY = 100)
        _GDIPlus_Startup()
        
        Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($new_W, $new_H)
        Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
        _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2)
        
        Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)
        _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $new_W, $new_H)
        _GDIPlus_ImageDispose($hImage)
        
        Local $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")
        Local $tParams = _GDIPlus_ParamInit(1)
        Local $tData = DllStructCreate("int Quality")
        Local $pData = DllStructGetPtr($tData)
        Local $pParams = DllStructGetPtr($tParams)
        DllStructSetData($tData, "Quality", $IQUALITY)
        _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData)
        _GDIPlus_ImageSaveToFileEx($hBitmap, $sFile_new, $sCLSID, $pParams)
        
        _GDIPlus_GraphicsDispose($hGraphics)
        _GDIPlus_BitmapDispose($hBitmap)
 
        _GDIPlus_Shutdown()
EndFunc
谢谢你的回答,但我这样还是不行。
发表于 2014-11-7 19:12:26 | 显示全部楼层
#include <GDIPlus.au3>

评分

参与人数 1金钱 +30 收起 理由
abcd1258 + 30 谢谢。已经解决。

查看全部评分

 楼主| 发表于 2014-11-7 19:39:53 | 显示全部楼层
#include
seniors 发表于 2014-11-7 19:12



    谢谢,已经解决。
发表于 2014-11-14 09:31:06 | 显示全部楼层
回复 6# abcd1258

已解決 請將帖子 標提改為 已解決
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 04:19 , Processed in 0.089071 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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