图片修改大小并支持图片预览
最近看上一个比较心仪的源码,无奈没钱下载,于是就发布一个刚写的代码,来赚钱小钱,代码不叫简陋,可能有很多修改的地方,也有一些地方运用手法也不怎么高明,仅作学习参考吧本代码可以批量导入图片,可以添加目录会自动筛选图片导入,也可以直接拖动图片进窗口,listview做了个简单排序,可以点击标题排序
下面是部分代码,全部的请下载附件#NoTrayIcon
#RequireAdmin
#Region ;**** 编译指令由 AutoIt3Wrapper 选项编译窗口创建 ****
#AutoIt3Wrapper_Icon=48x48.ico
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Description=修改图片大小,带图片预览
#AutoIt3Wrapper_Res_Fileversion=2.0
#AutoIt3Wrapper_Res_LegalCopyright=聆听天笑:281452390
#AutoIt3Wrapper_Res_Language=2052
#EndRegion ;**** 编译指令由 AutoIt3Wrapper 选项编译窗口创建 ****
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Array.au3>
#include <File.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
Global $DPIW ;分辨率宽
Global $ADDFolder ;添加目录
Global $One_File ;添加单个文件
Global $Dir;目录
Global $g_bSortSense = False ; 设置初始升序排序
$temp = @DesktopDir & "\图片修改"
;主窗口
$Form1 = GUICreate("修改图片大小V2.0", 640, 450, -1, -1, -1, $WS_EX_ACCEPTFILES)
GUISetFont(10, 400, 0, "微软雅黑")
GUISetBkColor(0xf0f0f0)
;图片保存地址
Global $Label1 = GUICtrlCreateLabel("输出目录", 10, 12, 70, 25)
Global $Input1 = GUICtrlCreateInput($temp, 70, 10, 300, 25)
Global $Button1 = GUICtrlCreateButton("修改", 380, 10, 60, 25)
;修改图片大小
GUICtrlCreateGroup("选择你要调整后图片的宽度(根据宽度等比缩放)", 10, 50, 430, 60)
GUICtrlSetColor(-1, 0xFFFFFF)
GUIStartGroup()
Global $Radio1 = GUICtrlCreateRadio("宽*600", 40, 75, 80, 20)
Global $Radio2 = GUICtrlCreateRadio("宽*800", 120, 75, 80, 20)
Global $Radio3 = GUICtrlCreateRadio("宽*1024(建议)", 200, 75, 120, 20)
Global $Radio4 = GUICtrlCreateRadio("宽*1440", 340, 75, 80, 20)
GUICtrlSetState($Radio3, $GUI_CHECKED)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;接受图片拖放区域
GUICtrlCreateLabel("已添加的图片(图片可以直接拖入下框,点击预览,双击打开,右键删除)", 10, 120, 430, 25)
Global $ListView = GUICtrlCreateListView("文件所在地址|分辨率|图片大小|修改时间", 10, 150, 620, 249,$LVS_SORTASCENDING,$LVS_EX_FULLROWSELECT+$LVS_EX_GRIDLINES)
_GUICtrlListView_SetColumnWidth($ListView, 0, 310)
_GUICtrlListView_SetColumnWidth($ListView, 1, 80)
_GUICtrlListView_SetColumnWidth($ListView, 2, 80)
_GUICtrlListView_SetColumnWidth($ListView, 3, 100)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
;功能按钮
Global $Button2 = GUICtrlCreateButton("添加图片目录", 20, 410, 100, 25)
Global $Button3 = GUICtrlCreateButton("添加单张图片", 135, 410, 100, 25)
Global $Button4 = GUICtrlCreateButton("修改图片", 250, 410, 80, 25)
Global $Button5 = GUICtrlCreateButton("清空图片", 345, 410, 80, 25)
Global $Help = GUICtrlCreateButton("查看帮助", 440, 410, 80, 25)
Global $Helpclose = GUICtrlCreateButton("关闭帮助", 535, 410, 80, 25)
;注册 Windows 消息
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW,$Form1)
;图片预览区域
$Form2 = GUICreate("图片预览区域", 180,125, 450, 10, $WS_CHILD+$WS_BORDER, -1,$Form1)
GUISetState(@SW_SHOW,$Form2)
_StringFormatCreate()
_help()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_MINIMIZE
SplashOff ( )
Case $Button1 ;选择图片保存目录
$SavePath = FileSelectFolder("选择图片保存目录", @DesktopDir, 1)
If Not @error Then
GUICtrlSetData($Input1, $SavePath)
EndIf
Case $Button2 ;添加图片目录
$ADDFolder = FileSelectFolder("选择图片目录", $Dir)
If Not @error Then
$Dir = $ADDFolder
_ByFolder($Dir)
EndIf
Case $Button3 ;添加图片
$FileList = FileOpenDialog("选择图片", $Dir, "图像文件 (*.jpg;*.bmp;*.gif;*.png)", 1 + 2 + 4)
If Not @error Then
_ByFiles($FileList)
EndIf
Case $Button4 ;修改图片
Local $Read_ADD ;读取添加在EDIT控件的内容
Local $ADD_File ;将$Read_ADD内容生成数组
If GUICtrlRead($Input1) = "" Then
MsgBox(64, "提示", "请选择修改后图片保存目录")
Else
If _GUICtrlListView_GetItemTextString($ListView, 0) = "||" Then
MsgBox(64, "提示", "你没添加图片")
Else
For $i = 0 To _GUICtrlListView_GetItemCount($ListView) - 1
$Read_ADD = _GUICtrlListView_GetItemTextString($ListView, $i)
_ArrayAdd($ADD_File, $Read_ADD)
Next
If GUICtrlRead($Input1)= $temp And NOT FileExists($temp ) Then
DirCreate(@DesktopDir & "\图片修改")
EndIf
If GUICtrlRead($Radio1) = $GUI_CHECKED Then $DPIW = "600"
If GUICtrlRead($Radio2) = $GUI_CHECKED Then $DPIW = "800"
If GUICtrlRead($Radio3) = $GUI_CHECKED Then $DPIW = "1024"
If GUICtrlRead($Radio4) = $GUI_CHECKED Then $DPIW = "1440"
For $i = 0 To UBound($ADD_File, 1) - 1
$name = _WinAPI_PathFindFileName($ADD_File[$i])
_GDIPlus_Startup()
Local $hImage = _GDIPlus_ImageLoadFromFile($ADD_File[$i])
Local $iX = _GDIPlus_ImageGetWidth($hImage)
Local $iY = _GDIPlus_ImageGetHeight($hImage)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
Local $newY = Round($DPIW / $iX * $iY, 0)
_PicChangeSize($ADD_File[$i], GUICtrlRead($Input1) & "\" & $DPIW & "X" & $newY & "-" & $name, $DPIW)
Next
$pid = MsgBox(0 + 4, "", "修改完成,是否打开修改后的图片目录")
If $pid = 6 Then
ShellExecute("explorer", GUICtrlRead($Input1))
EndIf
EndIf
EndIf
Case $Button5 ;清空
_GUICtrlListView_DeleteAllItems($ListView)
Case $Help
_help()
Case $Helpclose
SplashOff ( )
EndSwitch
WEnd 善于在论坛上学习新的东西 加油,以前我也写了个,半成品,用了一次后,就再也没有完整它的了。
顶一下
为何全是乱码啊,楼主 回复 4# fenhanxue
你的版本问题,换成utf8
页:
[1]