tic wrote:
try Gdip_BitmapReplaceColour:
Thanks! That works great. Now what I would like to do is make the white pixels transparent on a rotated bitmap. I have started merging the two scripts, and so far this is what I have:
Code:
SetBatchLines, -1
#Include, Gdip.ahk
If !pToken := Gdip_Startup()
{
MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
ExitApp
}
OnExit, Exit
Gui, 1: +ToolWindow +AlwaysOnTop
Gui, 1: Add, Edit, x10 y10 w300 vFile,
Gui, 1: Add, Button, x+10 yp+0 w75 gFileSelect Default, &File...
Gui, 1: Add, Button, x+10 yp+0 w75 gGo, &Go
Gui, 1: Add, Slider, x10 y+10 w300 Tooltip vAngle Range0-360, 0
Gui, 1: Add, CheckBox, x+10 yp+0 vHorizontal, Flip horizontally
Gui, 1: Add, CheckBox, x+10 yp+0 vVertical, Flip vertically
Gui, 1: Show, x0 y0 AutoSize
Gui, 2: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 2: Show, NA
hwnd2 := WinExist()
OnMessage(0x201, "WM_LBUTTONDOWN")
Return
;#####################################################################
Go:
Gui, 1: +OwnDialogs
Gui, 1: Submit, NoHide
If !pBitmap := Gdip_CreateBitmapFromFile(File)
Return
OriginalWidth := Gdip_GetImageWidth(pBitmap), OriginalHeight := Gdip_GetImageHeight(pBitmap)
Ratio := OriginalWidth/OriginalHeight
If (OriginalWidth >= A_ScreenWidth//1.312) || (OriginalHeight >= A_ScreenHeight//1.312)
{
If (OriginalWidth >= OriginalHeight)
Width := A_ScreenWidth//1.312, Height := Width*(1/Ratio)
Else
Height := A_ScreenHeight//1.312, Width := Height*Ratio
}
Else
Width := OriginalWidth, Height := OriginalHeight
Gdip_GetRotatedDimensions(Width, Height, Angle, RWidth, RHeight)
Gdip_GetRotatedTranslation(Width, Height, Angle, xTranslation, yTranslation)
hbm := CreateDIBSection(RWidth, RHeight)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc), Gdip_SetInterpolationMode(G, 7)
Gdip_TranslateWorldTransform(G, xTranslation, yTranslation)
Gdip_RotateWorldTransform(G, Angle)
If Horizontal
Gdip_ScaleWorldTransform(G, -1, 1), Gdip_TranslateWorldTransform(G, -Width, 0)
If Vertical
Gdip_ScaleWorldTransform(G, 1, -1), Gdip_TranslateWorldTransform(G, 0, -Height)
Gdip_DrawImage(G, pBitmap, 0, 0, Width, Height, 0, 0, OriginalWidth, OriginalHeight)
Gdip_ResetWorldTransform(G)
UpdateLayeredWindow(hwnd2, hdc, (A_ScreenWidth-RWidth)//1.312, (A_ScreenHeight-RHeight)//1.312, RWidth, RHeight)
SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap)
Return
;#####################################################################
; This is a simple subroutine to select images and change the editbox with the image teh user selects
FileSelect:
Gui, 1: +OwnDialogs
Gui, 1: Submit, NoHide
FileSelectFile, File,,, Select image
If Errorlevel
Return
GuiControl,, File, %File%
Return
;#####################################################################
WM_LBUTTONDOWN(wparam, lparam)
{
If (A_Gui = 2)
{
PostMessage, 0xA1, 2
global G, pBitmap, pBitmapOut, Width, Height, Variation, hwnd2, hdc
x := lparam & 0xffff, y := lParam >> 16
E := Gdip_BitmapReplaceColour(pBitmap, pBitmapOut, Gdip_GetPixel(pBitmap, x, y), 0x00000000, Variation)
Gdip_GraphicsClear(G)
Gdip_DrawImage(G, pBitmapOut)
UpdateLayeredWindow(hwnd2, hdc)
}
}
;#######################################################################
Gdip_BitmapReplaceColour(pBitmap, ByRef pBitmapOut, Colour, ReplaceColour, Variation)
{
static BitmapReplaceColour
if !BitmapReplaceColour
{
MCode_BitmapReplaceColour := "83EC248B4424388B4C243C995683E2038BF103C28B542438C1FE10C1F90881E6FF00000081E1FF000000C1F8028974"
. "2408894C244085D20F8E0A010000538B5C2430558B6C245033C903C0578B7C243C03C0894C241C89442430897C241889542420837C2440000F8EB9000"
. "0008D43018BD32BD083C202895424282BF5894C244403C88BD32BD08B442440897424248954242C89442410EB0B8DA424000000008B7424248B542428"
. "0FB6140A0FB6013BD67E0A8B74241403F53BD67C268B74244C2BF53BC67E248B5C244C03DD3BC38B5C24387C0E3BC67E128B74244C03F53BC67D088B4"
. "424508907EB228B7424440FB6741E03C1E6080BF28B54242CC1E6080BF00FB6040AC1E6080BF08937834424440483C10483C704FF4C241075828B4C24"
. "1C8B7424148B7C2418037C2430034C2448FF4C2420897C2418894C241C0F851EFFFFFF5F5D5BB8010000005E83C424C3"
VarSetCapacity(BitmapReplaceColour, StrLen(MCode_BitmapReplaceColour)//2)
Loop % StrLen(MCode_BitmapReplaceColour)//2 ;%
NumPut("0x" SubStr(MCode_BitmapReplaceColour, (2*A_Index)-1, 2), BitmapReplaceColour, A_Index-1, "char")
}
Width := Gdip_GetImageWidth(pBitmap), Height := Gdip_GetImageHeight(pBitmap)
if (Width != Gdip_GetImageWidth(pBitmapOut) || Height != Gdip_GetImageHeight(pBitmapOut))
return -1
if (Variation > 255 || Variation < 0)
return -2
E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1)
E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2)
if (E1 || E2)
return -3
E := DllCall(&BitmapReplaceColour, "uint", Scan01, "uint", Scan02, "int", Width, "int", Height, "int", Stride1, "int", Colour, "int", ReplaceColour, "int", Variation)
Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapOut, BitmapData2)
return 0
}
;#######################################################################
; If the user closes the gui or closes the program then we want to shut down gdi+ and exit the application
Esc::
GuiClose:
Exit:
Gdip_DisposeImage(pBitmapOut), Gdip_DisposeImage(pBitmap)
SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
ExitApp
Return
Eventually I'll have time to figure out what every line actually does, but sadly that won't be until I start on my next project sometime in 2011. Until then, I could use some more help. How else do I need to change
WM_LBUTTONDOWN(wparam, lparam) so that it works properly in the new script? Is there anywhere else so far that I have goofed? I'm pretty sure there is...

.
I really appreciate the help,
Sam.