#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <GDIPlus.au3>
Global $hGUI, $hPic, $hImage = 0, $hBitmap = 0
; GDI+ 초기화
_GDIPlus_Startup()
; GUI 생성
$hGUI = GUICreate("클립보드 이미지 뷰어", 800, 600, -1, -1, $WS_OVERLAPPEDWINDOW)
; 버튼 생성
$btnLoad = GUICtrlCreateButton("클립보드에서 가져오기", 10, 10, 150, 30)
$btnSave = GUICtrlCreateButton("이미지 저장", 170, 10, 100, 30)
$btnClear = GUICtrlCreateButton("지우기", 280, 10, 80, 30)
$lblInfo = GUICtrlCreateLabel("클립보드에 이미지가 없습니다", 400, 15, 350, 20)
; 이미지 표시 영역 (Pic 컨트롤)
$hPic = GUICtrlCreatePic("", 10, 50, 780, 540, $SS_NOTIFY)
GUISetState(@SW_SHOW, $hGUI)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
ExitLoop
Case $btnLoad
LoadImageFromClipboard()
Case $btnSave
SaveImage()
Case $btnClear
ClearImage()
EndSwitch
WEnd
; 종료 처리
Cleanup()
GUIDelete($hGUI)
_GDIPlus_Shutdown()
; ===== 함수 정의 =====
Func LoadImageFromClipboard()
; 기존 이미지 해제
If $hBitmap <> 0 Then
_GDIPlus_BitmapDispose($hBitmap)
$hBitmap = 0
EndIf
; 클립보드에서 비트맵 가져오기
$hBitmap = _ClipBoard_GetDataEx($CF_BITMAP)
If $hBitmap = 0 Then
GUICtrlSetData($lblInfo, "클립보드에 이미지가 없습니다")
MsgBox(48, "알림", "클립보드에 이미지가 없습니다.")
Return
EndIf
; GDI+ 비트맵으로 변환
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
If $hImage = 0 Then
GUICtrlSetData($lblInfo, "이미지 로드 실패")
MsgBox(16, "오류", "이미지를 로드할 수 없습니다.")
Return
EndIf
; 이미지 크기 가져오기
$iWidth = _GDIPlus_ImageGetWidth($hImage)
$iHeight = _GDIPlus_ImageGetHeight($hImage)
; 임시 파일로 저장 후 Pic 컨트롤에 표시
$sTempFile = @TempDir & "\clipboard_temp.bmp"
_GDIPlus_ImageSaveToFile($hImage, $sTempFile)
; Pic 컨트롤 크기 조정 및 이미지 설정
Local $picWidth = 780
Local $picHeight = 540
Local $ratio = 1
If $iWidth > $picWidth Or $iHeight > $picHeight Then
$ratio = ($iWidth / $picWidth > $iHeight / $picHeight) ? $picWidth / $iWidth : $picHeight / $iHeight
$iWidth = Int($iWidth * $ratio)
$iHeight = Int($iHeight * $ratio)
EndIf
GUICtrlSetPos($hPic, 10 + Int(($picWidth - $iWidth) / 2), 50 + Int(($picHeight - $iHeight) / 2), $iWidth, $iHeight)
GUICtrlSetImage($hPic, $sTempFile)
GUICtrlSetData($lblInfo, "이미지 로드됨: " & _GDIPlus_ImageGetWidth($hImage) & " x " & _GDIPlus_ImageGetHeight($hImage))
EndFunc
Func SaveImage()
If $hImage = 0 Then
MsgBox(48, "알림", "저장할 이미지가 없습니다.")
Return
EndIf
$sFile = FileSaveDialog("이미지 저장", @MyDocumentsDir, "이미지 파일 (*.png;*.jpg;*.bmp)|모든 파일 (*.*)", 16, "screenshot.png")
If @error Then Return
; 파일 확장자 확인
If StringRight($sFile, 4) <> ".png" And StringRight($sFile, 4) <> ".jpg" And StringRight($sFile, 4) <> ".bmp" Then
$sFile &= ".png"
EndIf
_GDIPlus_ImageSaveToFile($hImage, $sFile)
If FileExists($sFile) Then
MsgBox(64, "완료", "이미지가 저장되었습니다:" & @CRLF & $sFile)
Else
MsgBox(16, "오류", "이미지 저장에 실패했습니다.")
EndIf
EndFunc
Func ClearImage()
GUICtrlSetImage($hPic, "")
GUICtrlSetData($lblInfo, "클립보드에 이미지가 없습니다")
If $hImage <> 0 Then
_GDIPlus_ImageDispose($hImage)
$hImage = 0
EndIf
If $hBitmap <> 0 Then
_WinAPI_DeleteObject($hBitmap)
$hBitmap = 0
EndIf
; 임시 파일 삭제
FileDelete(@TempDir & "\clipboard_temp.bmp")
EndFunc
Func Cleanup()
ClearImage()
; 임시 파일 정리
FileDelete(@TempDir & "\clipboard_temp.bmp")
EndFunc
; 클립보드에서 데이터 가져오기 함수
Func _ClipBoard_GetDataEx($iFormat)
If Not _ClipBoard_Open(0) Then Return SetError(1, 0, 0)
Local $hData = _ClipBoard_GetData($iFormat)
_ClipBoard_Close()
Return $hData
EndFunc