AutoHotkey Community

It is currently May 26th, 2012, 2:36 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1000 posts ]  Go to page Previous  1 ... 10, 11, 12, 13, 14, 15, 16 ... 67  Next
Author Message
 Post subject:
PostPosted: January 25th, 2009, 9:00 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
If enough people want a help file for gdi+ ill make one.

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2009, 9:04 pm 
Online
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Open a Poll.. I vote +1


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2009, 9:07 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Ok. Poll here:
http://www.autohotkey.com/forum/viewtop ... 791#245791

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 25th, 2009, 11:52 pm 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2009, 2:43 am 
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



Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2009, 10:48 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 26th, 2009, 4:13 pm 
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? :D Sincerely, Nicklea


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2009, 8:38 am 
TIC, you are so great, have a wonderful day! thank you!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 1st, 2009, 4:50 am 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2009, 7:52 pm 
bump! :)

Say, does anyone know how to do this? ^ <:->


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 3rd, 2009, 7:53 pm 
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 :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 4th, 2009, 11:29 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 5th, 2009, 7:11 pm 
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! :D 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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 8th, 2009, 10:28 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
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).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 8th, 2009, 9:57 pm 
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 :cool:


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1000 posts ]  Go to page Previous  1 ... 10, 11, 12, 13, 14, 15, 16 ... 67  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: daonlyfreez, Google Feedfetcher, mhe and 13 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group