Hi,jj2007
the GdipDrawImageRectRectI is not for cropping.
try to test this.
option casemap:none
option win64:7
include \UASM64\include\windows.inc
include \UASM64\include\gdiplus.inc
include \UASM64\include\commctrl.inc
includelib \UASM64\Lib\user32.lib
includelib \UASM64\Lib\kernel32.lib
includelib \UASM64\Lib\gdi32.lib
includelib \UASM64\Lib\gdiplus.lib
IDI_MAINICO equ 100
IDD_DIALOG1 equ 1000
IDC_STATIC1 equ 1001
BTN_ORIGINAL equ 1002
BTN_COMPRESSED equ 1003
BTN_EXPANDED equ 1004
.data?
hInstance dq ?
hWinMain dq ?
m_gdiplusToken dd ?
m_OlgStaticPrc dq ?
dqMethod dq ? ; 0:original , 1:compressed , 2:expanded
.data
szImageFile db "p111.png",0
.code
OnGdiPlusDraw proc hDC:HDC,_Method:qword
local @pGraphics:QWORD
local @image:QWORD
local @Width:DWORD
local @Height:DWORD
local @buf[32]:WORD
invoke GdipCreateFromHDC,hDC,addr @pGraphics
invoke MultiByteToWideChar,CP_ACP,0,addr szImageFile,-1,addr @buf,32
invoke GdipLoadImageFromFile,addr @buf,addr @image
invoke GdipGetImageWidth,@image,addr @Width
invoke GdipGetImageHeight,@image,addr @Height
.if _Method == 1
mov eax,@Width
shr eax,1 ; @Width = @Width/2
mov @Width,eax
mov eax,@Height
shr eax,1 ; @Height = @Height/2
mov @Height,eax
.elseif _Method == 2
mov eax,@Width
shl eax,1 ; @Width = @Width*2
mov @Width,eax
mov eax,@Height
shl eax,1 ; @Height = @Height*2
mov @Height,eax
.endif
invoke GdipDrawImageRectI,@pGraphics,@image,1,1,@Width,@Height
invoke GdipDisposeImage,@image
invoke GdipDeleteGraphics,@pGraphics
ret
OnGdiPlusDraw endp
InitGgdplus proc
local @gdis:GdiplusStartupInput
mov @gdis.GdiplusVersion,1
mov @gdis.DebugEventCallback,0
mov @gdis.SuppressBackgroundThread,0
mov @gdis.SuppressExternalCodecs,0
invoke GdiplusStartup,addr m_gdiplusToken,addr @gdis,NULL
ret
InitGgdplus endp
_StaticProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
local @ps:PAINTSTRUCT
mov eax,uMsg
.if eax == WM_PAINT
invoke BeginPaint,hWnd,addr @ps
invoke GetStockObject, WHITE_BRUSH ;LTGRAY_BRUSH
invoke FillRect,@ps.hdc,addr @ps.rcPaint,rax
invoke OnGdiPlusDraw,@ps.hdc,dqMethod
invoke EndPaint,hWnd,addr @ps
.else
invoke CallWindowProc,m_OlgStaticPrc,hWnd,uMsg,wParam,lParam
mov rax,FALSE
ret
.endif
mov rax,TRUE
ret
_StaticProc endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
mov eax,uMsg
.if eax == WM_INITDIALOG
invoke LoadIcon,hInstance,IDI_MAINICO
invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,rax
invoke GetDlgItem,hWnd,IDC_STATIC1
invoke SetWindowLongPtr,rax,GWL_WNDPROC, addr _StaticProc
.if rax == NULL
invoke MessageBox,0,CStr("SetWindowLong error"),0,0
.else
mov m_OlgStaticPrc,rax
.endif
.elseif eax == WM_COMMAND
mov rax,wParam
.if ax==BTN_ORIGINAL
mov dqMethod,0
.elseif ax==BTN_COMPRESSED
mov dqMethod,1
.elseif ax==BTN_EXPANDED
mov dqMethod,2
.endif
invoke GetDlgItem,hWnd,IDC_STATIC1
invoke InvalidateRect,rax,0,1
.elseif eax == WM_CLOSE
invoke EndDialog,hWnd,0
.else
mov rax,FALSE
ret
.endif
mov rax,TRUE
ret
WndProc endp
WinMainCRTStartup Proc
invoke GetModuleHandle,NULL
mov hInstance,rax
invoke InitGgdplus
invoke DialogBoxParam,hInstance,IDD_DIALOG1,0,addr WndProc,0
invoke GdiplusShutdown,m_gdiplusToken
invoke ExitProcess,NULL
WinMainCRTStartup Endp
end
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include <\UASM64\include\resource.h>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#define IDI_MAINICO 100
#define IDD_DIALOG1 1000
#define IDC_TOOLBAR 1000
#define IDC_STATIC1 1001
#define BTN_ORIGINAL 1002
#define BTN_COMPRESSED 1003
#define BTN_EXPANDED 1004
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
IDD_DIALOG1 DIALOG 0, 0, 310,200
STYLE DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "GDI-Test"
FONT 10, "MS Serif"
BEGIN
LTEXT "",IDC_STATIC1,1,1,308,180,WS_BORDER
PUSHBUTTON "Original", BTN_ORIGINAL, 2,183,50,14
PUSHBUTTON "Compressed", BTN_COMPRESSED,54,183,50,14
PUSHBUTTON "Expanded", BTN_EXPANDED, 106,183,50,14
END
100 ICON "main.ico"
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>