 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Frankie
Joined: 02 Nov 2008 Posts: 2850
|
Posted: Sun Jan 25, 2009 8:00 pm Post subject: |
|
|
If enough people want a help file for gdi+ ill make one. _________________ aboutscript ⍟ apps ⍟ scripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Sun Jan 25, 2009 8:04 pm Post subject: |
|
|
| Open a Poll.. I vote +1 |
|
| Back to top |
|
 |
Frankie
Joined: 02 Nov 2008 Posts: 2850
|
|
| Back to top |
|
 |
Joy2DWorld
Joined: 04 Dec 2006 Posts: 561 Location: Galil, Israel
|
Posted: Sun Jan 25, 2009 10:52 pm Post subject: |
|
|
just to beat on the Win'95 thing,
maybe GDI+ not best tool to use for graphics stuff...
eg., DirectX or OpenGL instead ?
(o think there is OGL for '95 (?).
just a thought. not necessarily a correct one! _________________ Joyce Jamce |
|
| Back to top |
|
 |
DG Guest
|
Posted: Mon Jan 26, 2009 1:43 am Post subject: |
|
|
| Frankie wrote: | | If enough people want a help file for gdi+ ill make one. |
Hi Frankie, I am very interesting in one thing. To demonstrate a GUI window I can do few things:
1) Pick from 4 colors, RED, BLUE, GREEN, YELLOW
2) Draw using a thick crayon size paintbrush on GUI
3) Save drawn image to a pBitmap
.. but mainly I can never figure out how to collect the drawn image for pBitmap
... how to do this?
this is what I have been working with so far
| Code: |
SetBatchLines, -1
Process, Exist
Process, priority, %ErrorLevel%, High
OnExit, Exit
Gui, Show, h300 w300, Test
Gui, Add, Button, x10 y10 w270 h25 , Save To pBitmap/hBitmap
hWnd := WinExist("Test")
hDC := DllCall("GetDC", UInt, hWnd)
color := 0xFF0000FF
OnMessage(0x201, "Draw")
Return
LButton::
Loop
If GetKeyState("Lbutton", "P")
Click
Else
break
Return
Draw(wParam, lParam)
{
Global hDC, color
DllCall("SetPixel", UInt, hDC, Int, lParam & 0xFFFF, Int, lParam >> 16, UInt, color)
}
GuiClose:
GuiEscape:
Exit:
If hDC
DllCall("ReleaseDC", UInt, hDC)
ExitApp
|
|
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1786
|
Posted: Mon Jan 26, 2009 9:48 am Post subject: |
|
|
DG, I had already posted something similar for skrommel. Double click the tray icon to toggle modes......
| Code: | #SingleInstance, Force
DetectHiddenWindows, On
#NoEnv
SetBatchLines, -1
Coordmode, Pixel, Screen
Coordmode, Mouse, Screen
AppName = Desktop.Painter
VersionNum = 1.02
ColourN = Red|Green|Blue
ColourH = ffff0000|ff00ff00|ff0000ff
StringSplit, ColourN, ColourN, |
StringSplit, ColourH, ColourH, |
SW := 50
BackColour := 0xff475155
#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
Menu, Tray, NoStandard
Menu, Tray, DeleteAll
Menu, Tray, Add, Toggle Notes, ToggleNotes
Menu, Tray, Add, Exit, Exit
Menu, Tray, Default, Toggle Notes
SysGet, MonitorPrimary, MonitorPrimary
SysGet, WA, MonitorWorkArea, %MonitorPrimary%
WAWidth := WARight-WALeft, WAHeight := WABottom-WATop
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 1: Show, NA Hide
hwnd1 := WinExist()
Gui, 2: -Caption +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs +Owner1
hwnd2 := WinExist()
Gui, 2: Color, 475155
Gui, 2: Add, Button, x135 y10 w50 gSave Default, &Save...
Loop, %ColourN0%
{
Gui, 2: Add, Picture, % ((A_Index = 1) ? "x15 y+10" : "x+10 yp+0") " w" SW " h" SW " gChangeColour 0xE v" ColourH%A_Index% " hwnd" ColourN%A_Index%
pBrush := Gdip_BrushCreateSolid("0x" ColourH%A_Index%)
pBitmap := Gdip_CreateBitmap(SW, SW), G := Gdip_GraphicsFromImage(pBitmap)
Gdip_FillRectangle(G, pBrush, 0, 0, SW, SW)
hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
hwnd := ColourN%A_Index%, SetImage(%hwnd%, hBitmap)
Gdip_DeleteBrush(pBrush), Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
}
Gui, 2: Add, Picture, % "x75 y+30 w" SW " h" SW " 0xE hwndPreview" ;%
Gui, 2: Add, Slider, x10 y+40 w180 vPenWidth Tooltip Range1-30 gUpdatePreview, 12
ChosenColour := 0xffff0000
GoSub, UpdatePreview
Gui, 2: Show, w200 h250 x20 y20 NA Hide
pBitmapDraw := Gdip_CreateBitmap(WAWidth, WAHeight), GDrawplus := Gdip_GraphicsFromImage(pBitmapDraw)
Gdip_SetSmoothingMode(GDrawplus, 4)
hbmDraw := CreateDIBSection(WAWidth, WAHeight), hdcDraw := CreateCompatibleDC(), obmDraw := SelectObject(hdcDraw, hbmDraw), GDraw := Gdip_GraphicsFromHDC(hdcDraw)
Gdip_SetSmoothingMode(GDraw, 4)
pBrush := Gdip_BrushCreateSolid(0x01ffffff)
Gdip_FillRectangle(GDrawplus, pBrush, 0, 0, WAWidth, WAHeight), Gdip_FillRectangle(GDraw, pBrush, 0, 0, WAWidth, WAHeight)
Gdip_DeleteBrush(pBrush)
UpdateLayeredWindow(hwnd1, hdcDraw, WALeft, WATop, WAWidth, WAHeight)
Return
;####################################################################################
Save:
Gui, 2: +OwnDialogs
FileSelectFolder, OutFolder,,, Select where you would like to save the image
If !OutFolder
Return
Gdip_SaveBitmapToFile(pBitmapDraw, OutFolder "\" A_Now ".png")
Return
;####################################################################################
UpdatePreview:
Gui, 2: Submit, NoHide
pBrush := Gdip_BrushCreateSolid(ChosenColour)
pBrushBack := Gdip_BrushCreateSolid(BackColour)
pBitmap := Gdip_CreateBitmap(SW, SW), G := Gdip_GraphicsFromImage(pBitmap), Gdip_SetSmoothingMode(G, 4)
Gdip_FillRectangle(G, pBrushBack, -2, -2, SW+4, SW+4)
Gdip_FillEllipse(G, pBrush, (SW-PenWidth)//2, (SW-PenWidth)//2, PenWidth, PenWidth)
hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
SetImage(Preview, hBitmap)
Gdip_DeleteBrush(pBrushDraw), Gdip_DeletePen(pPenDraw)
pBrushDraw := Gdip_BrushCreateSolid(ChosenColour), pPenDraw := Gdip_CreatePen(ChosenColour, PenWidth)
Gdip_DeleteBrush(pBrush), Gdip_DeleteBrush(pBrushBack), Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap)
Return
;####################################################################################
ChangeColour:
ChosenColour := "0x" A_GuiControl
GoSub, UpdatePreview
Return
;####################################################################################
WM_LBUTTONDOWN()
{
Global
If (A_Gui != 2)
Return, -1
PostMessage, 0xA1, 2
Drag := 1
}
;####################################################################################
ToggleNotes:
v := IsWindowVisible(hwnd1) || IsWindowVisible(hwnd2)
Gui, % "2: " (v ? "Hide" : "Show") ;%
Gui, % "1: " (v ? "Hide" : "Show") ;%
SetTimer, CheckPos, % (v ? "Off" : 40) ;%
Return
;####################################################################################
CheckPos:
Critical
MouseGetPos, x, y, Win
OnMessage(0x201, (Win = hwnd2) ? "WM_LBUTTONDOWN" : "")
If !GetKeyState("LButton", "P")
Drag := 0
If (Win != hwnd1) || !GetKeyState("LButton", "P") || Drag
{
Ox := Oy := ""
Return
}
SetTimer, DelayedSave, Off
Gdip_FillEllipse(GDraw, pBrushDraw, x-(PenWidth//2), y-(PenWidth//2), PenWidth, PenWidth)
Gdip_DrawLine(GDraw, pPenDraw, Ox ? Ox : x, Oy ? Oy : y, x, y)
UpdateLayeredWindow(hwnd1, hdcDraw, WALeft, WATop, WAWidth, WAHeight)
Array .= x "," y "," Ox "," Oy "|"
SetTimer, DelayedSave, -300
Ox := x, Oy := y
Return
;####################################################################################
DelayedSave:
Critical
Loop, Parse, Array, |
{
StringSplit, c, A_LoopField, `,
Gdip_FillEllipse(GDrawplus, pBrushDraw, c1-(PenWidth//2), c2-(PenWidth//2), PenWidth, PenWidth)
Gdip_DrawLine(GDrawplus, pPenDraw, c3 ? c3 : c1, c4 ? c4 : c2, c1, c2)
}
Array := ""
Return
;####################################################################################
IsWindowVisible(hwnd)
{
Return, DllCall("IsWindowVisible", "UInt", hwnd)
}
;####################################################################################
Exit:
Gdip_DeleteBrush(pBrushDraw), Gdip_DeletePen(pPenDraw)
Gdip_DeleteGraphics(GDrawplus), Gdip_DisposeImage(pBitmapDraw)
Gdip_DeleteGraphics(GDraw), SelectObject(hdcDraw, obmDraw), DeleteObject(hbmDraw), DeleteDC(hdcDraw)
Gdip_Shutdown(pToken)
ExitApp
Return |
Nicklea:
You could try changing the colours using a matrix when drawing
| Code: | | Gdip_DrawImage(pGraphics, pBitmap, dx, dy, dw, dh, sx="", sy="", sw="", sh="", Matrix=1) |
Try using the ones in gdip.ahk as a test:
| Code: | ;MatrixBright = 1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1
;MatrixGreyScale = 0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1
;MatrixNegative = -1|0|0|0|0|0|1|0|0|0|0|0|-1|0|0|0|0|0|1|0|0|0|0|0|1 |
Also I will look into using the clipboard with gdip when I get time
Thanks all |
|
| Back to top |
|
 |
Nicklea Guest
|
Posted: Mon Jan 26, 2009 3:13 pm Post subject: |
|
|
Dear Tic,
Thank you! This is immensely helpful and I almost seem to have the function running. Please see my results beneath.
NOTE: using my code logic below, Matrix does not seem to have any affect on the displayed image, although I am successfully able to display the image.
I am not sure how to use the Matrix definitions (the 1|0|0|0 stuff)... but it appears when I call Gdip_DrawImage, I am getting a non-blank in the MSGBOX below, so it seems to be doing something....
My goal is to change pImage from a partially transparent 100% white image, to a equivalent-transparent 100% RED image.
| Code: |
Gdip_DrawImage(pGraphics, pImage, x, y, w, h, sx="", sy="", sw="", sh="", Matrix=1)
{
If (Matrix&1 = "")
ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
Else
ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1")
MsgBox, %ImageAttr%
E := DllCall("gdiplus\GdipDrawImageRectI", "UInt", pGraphics, "UInt", pImage
, "int", x, "int", y, "int", w, "int", h
, "Float", sx, "Float", sy, "Float", sw, "Float", sh
, "Int", 2, "UInt", ImageAttr, "UInt", 0, "UInt", 0)
If ImageAttr
Gdip_DisposeImageAttributes(ImageAttr)
Return, E
}
|
| Code: |
Gdip_DrawImage(pGraphics, pBitmap, x, y, w, h, sx="",sy="",sw="",sh="",Matrix=1)
|
I am not sure why ImageAttr seems to have no affect against pImage. Can you see what I am doing wrong, and how to fine tune Matrix so I can pick solid conversion colors in a clear-cut way? Sincerely, Nicklea |
|
| Back to top |
|
 |
DG Guest
|
Posted: Tue Jan 27, 2009 7:38 am Post subject: |
|
|
| TIC, you are so great, have a wonderful day! thank you! |
|
| Back to top |
|
 |
Nicklea Guest
|
Posted: Sun Feb 01, 2009 3:50 am Post subject: |
|
|
Dear Tic, thank you for this thread. I love your functions,... but still stumbling with one or two concepts.
I am confused about Color Matrix and its applications, ... and I am unsure if I should focus on that, or maybe you can help me focus on what I should looking for if that isn't right.
MY GOAL:::
Basically, I want to take a image and apply a simple color overlay.
Some background: Photoshop has a option called 'color overlay' which basically takes whatever you've got image wise, and applies a full 100% color overlay against the image, depending on what color you want to apply.
The catch is, if there is some semi-transparency, the applied color is saturated into the gradient of the transparency...
I am posting myself well. I posted a sample before and can post a new one
Would color matrix some how help me reach my goal? I would like to experiment with some ideas, but don't really have a starting place to go from, and maybe you can key me in on a idea or two.
Best wishes, Nicklea. |
|
| Back to top |
|
 |
Nicklea Guest
|
Posted: Tue Feb 03, 2009 6:52 pm Post subject: |
|
|
bump!
Say, does anyone know how to do this? ^ <:-> |
|
| Back to top |
|
 |
Nicklea Guest
|
Posted: Tue Feb 03, 2009 6:53 pm Post subject: |
|
|
btw, please, If my question isn't 100% understanding, please let me know, I... don't know if the gdip question was too overly technical asd described  |
|
| Back to top |
|
 |
tic
Joined: 22 Apr 2007 Posts: 1786
|
Posted: Wed Feb 04, 2009 10:29 am Post subject: |
|
|
| I will explain how to use colour matrices soon, but they still will probably not do entirely what you need to do, and would need either a machine code function or to do it in a compiled langauge |
|
| Back to top |
|
 |
Nicklea Guest
|
Posted: Thu Feb 05, 2009 6:11 pm Post subject: |
|
|
| tic wrote: | | I will explain how to use colour matrices soon, but they still will probably not do entirely what you need to do, and would need either a machine code function or to do it in a compiled langauge |
Coolness! I thank you so much for checking into it.
I think the images I posted before was terrible. Below is a crisper version of it,
Hello, I have this problem. Before I draw a Bitmap, I want to change all visible pixels to a single color, and retain transparency.
Here is an example:
Can I go from:
http://www.merrypic.com/files/kuhov6q8atcz2itnvhqf.gif
To this?
http://www.merrypic.com/files/euexj87o51wwraxpnm1t.gif |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7299 Location: Australia
|
Posted: Sun Feb 08, 2009 9:28 am Post subject: |
|
|
tic, I have a few suggestions:
- When the source co-ordinates are omitted from DrawImage, default to the entire image. Currently if I say "draw an image at 0,0 and make it 100x100" and the image is only 16x16, the result will be 16x16. GDI+ offers overloads of DrawImage() which accept only a pair of co-ordinates, and will draw the entire image at those co-ordinates. These are available in the flat API; alternatively, you could simulate them by retrieving the size of the image.
- Similarly, allow the destination size to be omitted.
- Implement a wrapper for GdipCreateBitmapFromScan0 (beyond the simple Gdip_CreateBitmap), which can be used to create a bitmap from bitmap data. Example.
- Implement a wrapper for GdipGraphicsClear (I've suggested this before).
|
|
| Back to top |
|
 |
Nicklea Guest
|
Posted: Sun Feb 08, 2009 8:57 pm Post subject: |
|
|
say Lexikos, you seem to know many tons, just curious if you can see my vision from Post before the last,... and know something i may try to re-draw bitmaps with one solid color 'overlay', however keeping transparency levels all the same no matter how complex the image, it just becomes a flat image with only one desired color.... so, for example, a white gradient block or triangle may become yellow, orange, or blue or xxx .... andlike if the edges are semi-transparent already, those are preserved, and will become same appropriately yellow, orange or blue.
i am doing some graphic object transforming, with hundreds of potential partially trans. images of many shapes, ... and trying to save tons of resources so i don't need to duplicate those images over and over by hand with different colors. i posted a couple examples. thanks for looking! i appreciate it  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|