AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GDI+ standard library 1.45 by tic
Goto page Previous  1, 2, 3 ... 23, 24, 25 ... 60, 61, 62  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
tic



Joined: 22 Apr 2007
Posts: 1786

PostPosted: Fri Mar 12, 2010 12:15 am    Post subject: Reply with quote

Hehe....yeh Smurth is right. You have written:

Code:
; Set the smoothing mode to antialias = 4 to make shapes appear smother (only used for vector drawing and filling)
Gdip_SetSmoothingMode(G, 4)


but your graphics is called p_graphic!

Yeh, sure....no probs infogulch......what are you using it for?
Back to top
View user's profile Send private message
Razer



Joined: 15 Feb 2010
Posts: 10

PostPosted: Fri Mar 12, 2010 3:10 pm    Post subject: Reply with quote

Thx guys,

It's so good to have these nice rounded shapes ^^

Razer.
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 649

PostPosted: Fri Mar 12, 2010 6:02 pm    Post subject: Reply with quote

Thanks tic. I'm planning on releasing a new version of my RegionGetColor script soon, and it requires the GetCompatibleBitmap function. Currently I'm using my own mfc wrapper, but one of the new examples requires GDIP, so I'd like to prevent conflicts... meh, it's hard to explain.

Actually I would appreciate if you could help me review it before it's released. Would it be alright if I pm'd you about it later?
_________________
Scripts - License
Back to top
View user's profile Send private message
evandevon



Joined: 22 Apr 2008
Posts: 82

PostPosted: Thu Mar 25, 2010 4:04 pm    Post subject: Reply with quote

Hi Tic!
Does you're program do spline curves? I had a lil look but I couldn't see anything. I'm designing an app:

http://www.autohotkey.com/forum/viewtopic.php?p=342344#342344

And for it to work I need to feed up to around 6 co-ordinates (x,y) and have a path returned.

Anything like it in there?

Thanks, Evs.
_________________
Inventing problems that need solutions...

Open Communicator
MouseTrainer
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1786

PostPosted: Fri Mar 26, 2010 12:02 am    Post subject: Reply with quote

evandevon wrote:
Hi Tic!
Does you're program do spline curves? I had a lil look but I couldn't see anything. I'm designing an app:

http://www.autohotkey.com/forum/viewtopic.php?p=342344#342344

And for it to work I need to feed up to around 6 co-ordinates (x,y) and have a path returned.

Anything like it in there?

Thanks, Evs.


Gdip_DrawBezier
Back to top
View user's profile Send private message
evandevon



Joined: 22 Apr 2008
Posts: 82

PostPosted: Sun Mar 28, 2010 12:46 am    Post subject: Reply with quote

Hi Tic! Thanks for your quick reply!

Sorry if it's an obvious thing to figure out but I seem to be out of my depth for now. From what I understand Gdip_DrawBezier only gets fed points and then outputs a bezier path to the screen. Is there a way to get each x,y co-ordinate for each pixel of that path? I need to be able to move the mouse along the path.

For example could i move the mouse to the first point i fed into DrawBezier, then could I re-send in the next x pixel along and get returned the y value for that x value? Then I could move the mouse to that point and repeat and get a smooth curved mouse movement.

Thanks again, Evs.
_________________
Inventing problems that need solutions...

Open Communicator
MouseTrainer
Back to top
View user's profile Send private message
Lithodora



Joined: 02 Jul 2006
Posts: 23

PostPosted: Tue Apr 06, 2010 10:55 pm    Post subject: Reply with quote

tic wrote:
Equivalent gdi+ could be:

Code:

ConvertImage(sInput, sOutput, Width="", Height="", Method="Percent")
{
   pBitmap := Gdip_CreateBitmapFromFile(sInput)
   Width := Gdip_GetImageWidth(pBitmap), Height := Gdip_GetImageHeight(pBitmap)
   
   If (Method = "Percent")
   {
      Width := (Width = -1) ? Height : Width, Height := (Height = -1) ? Width : Height
      dWidth := Round(sWidth*(Width/100)), dHeight := Round(sHeight*(Height/100))
   }
   else If (Method = "Pixels")
   {
      if (Width = -1)
      dWidth := Round((Height/sHeight)*sWidth), dHeight := Height
      else if (Height = -1)
      dHeight := Round((Width/sWidth)*sHeight), dWidth := Width
      else
      dWidth := Width, dHeight := Height
   }
   else
      return -1

   pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight)
   G1 := Gdip_GraphicsFromImage(pBitmap1), Gdip_SetInterpolationMode(G1, 7)

   Gdip_SaveBitmapToFile(pBitmap, sOutput)
   Gdip_DeleteGraphics(G1)
   Gdip_DisposeImage(pBitmap), Gdip_DisposeImage(pBitmap1)
   return 0
}


I havent tested this and didnt really do any error checks. The original has been superceded by the gdi+ lib as it allows a lot more control of what is going on. You can look at the examples for ideas


I know you said it wasn't tested, but I can't make it work. It saves the file with the original Height/Width. I think there is a line missing drawing the pBitmap to the pBitmap1 file. I just have no idea how to make that work, perhaps I just don't know what I'm doing...


Here's the slight changes I made to correct the math:
Code:

/*Resize images
*/
ConvertImage(sInput, sOutput, Width="", Height="", Method = "Pixels")
{
   pBitmap := Gdip_CreateBitmapFromFile(sInput)
   aWidth := Gdip_GetImageWidth(pBitmap), aHeight := Gdip_GetImageHeight(pBitmap)
   
   If (Method = "Percent")
   {
      Width := (Width = -1) ? Height : Width, Height := (Height = -1) ? Width : Height
      dWidth := Round(Width*(aWidth/100)), dHeight := Round(Height*(aHeight/100))
   }
   else If (Method = "Pixels")
   {
      if (Width = -1)
      dWidth := Round(aWidth/(aHeight/Height)), dHeight := Height
      else if (Height = -1)
      dHeight := Round(aHeight/(aWidth/Width)), dWidth := Width
      else
     {
      dWidth := Width, dHeight := Height
     }
   }
   else
      return -1

   pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight)
   G1 := Gdip_GraphicsFromImage(pBitmap1), Gdip_SetInterpolationMode(G1, 7)

   Gdip_SaveBitmapToFile(pBitmap, sOutput)
   Gdip_DeleteGraphics(G1)
   Gdip_DisposeImage(pBitmap), Gdip_DisposeImage(pBitmap1)
   return 0
}
Back to top
View user's profile Send private message
SifJar



Joined: 13 Feb 2010
Posts: 170

PostPosted: Wed Apr 07, 2010 7:07 pm    Post subject: Reply with quote

EDIT: Never mind, n00bish mistakes i fixed with a couple of minutes thought.
Back to top
View user's profile Send private message
evandevon



Joined: 22 Apr 2008
Posts: 82

PostPosted: Fri Apr 30, 2010 1:54 pm    Post subject: Reply with quote

Anyone have any ideas for my previous post? It's about 3 posts up...
_________________
Inventing problems that need solutions...

Open Communicator
MouseTrainer
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1786

PostPosted: Fri Apr 30, 2010 3:58 pm    Post subject: Reply with quote

evandevon wrote:
Anyone have any ideas for my previous post? It's about 3 posts up...


Sorry evandevon.....Gdip is a drawing library so it wouldnt return the x and y coordinates as it just performs the drawing. You would need to use the formula of a bezier to work this out:

http://www.cl.cam.ac.uk/teaching/2000/AGraphHCI/SMEG/node3.html
Back to top
View user's profile Send private message
evandevon



Joined: 22 Apr 2008
Posts: 82

PostPosted: Sat May 01, 2010 4:23 am    Post subject: Reply with quote

Thanks Tic! Unfortunately Iīve tried to learn bezier formulas during my searches but canīt really get my head round them. As a dodgy work around what do you think about drawing a curve on screen between 1-n points then doing a pixel colour search starting at pixels next to the first point and move the mouse to the matching point, then check the next local pixels and repeat? I donīt have access to my machine so I canīt really knuckle down and test if pixel search works on colours drawn by gdi+ can someone check this for me? And if they are feeling particularly generous and have some free time on their hands maybe they could begin a little app that accepts n points, displays a curve, then moves the mouse along that curve for me? Iīm travelling at the moment and only have a few minutes access to internet cafes every blue moon for the next month. Any advice/help is greatly appreciated.
Thanks, Evs.
P.S. As motivation, this is part of a project Iīm working on to help severely physically disabled artists use a single switch input to paint on a computer.
Project discussion:
http://www.autohotkey.com/forum/viewtopic.php?t=56061&highlight=gravitational
_________________
Inventing problems that need solutions...

Open Communicator
MouseTrainer
Back to top
View user's profile Send private message
Murp|e



Joined: 12 Jan 2007
Posts: 531
Location: Norway

PostPosted: Wed May 05, 2010 1:28 pm    Post subject: Reply with quote

I'm creating a script that loads a series of JPG images into memory with Gdip_CreateBitmapFromFile and then displays them on screen. I have a function called ShowImage which is meant to receive a pBitmap and display it on the screen in full size, this function fails with a C++ runtime error if I try to load the same pBitmap twice and I don't understand how GDI works so I'm having err... I'm having trouble troubleshooting. The script is based on Example 3 - Create a gui from an existing image on disk. Here is the function:

Code:
Showimage(pBitmap)
{
global

; Get the width and height of the bitmap we have just created from the file
; This will be the dimensions that the file is
Width := Gdip_GetImageWidth(pBitmap)
Height := Gdip_GetImageHeight(pBitmap)

; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
; We are creating this "canvas" at half the size of the actual image
; We are halving it because we want the image to show in a gui on the screen at half its dimensions
hbm := CreateDIBSection(A_ScreenWidth, A_ScreenHeight)
;hbm := CreateDIBSection(Width, Height)

; Get a device context compatible with the screen
hdc := CreateCompatibleDC()

; Select the bitmap into the device context
obm := SelectObject(hdc, hbm)

; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromHDC(hdc)

; We do not need SmoothingMode as we did in previous examples for drawing an image
; Instead we must set InterpolationMode. This specifies how a file will be resized (the quality of the resize)
; Interpolation mode has been set to HighQualityBicubic = 7
Gdip_SetInterpolationMode(G, 7)

; DrawImage will draw the bitmap we took from the file into the graphics of the bitmap we created
; We are wanting to draw the entire image, but at half its size
; Coordinates are therefore taken from (0,0) of the source bitmap and also into the destination bitmap
; The source height and width are specified, and also the destination width and height (half the original)
; Gdip_DrawImage(pGraphics, pBitmap, dx, dy, dw, dh, sx, sy, sw, sh, Matrix)
; d is for destination and s is for source. We will not talk about the matrix yet (this is for changing colours when drawing)
;Gdip_DrawImage(G, pBitmap, 0, 0, Width, Height, 0, 0, Width, Height)
Gdip_DrawImage(G, pBitmap, 0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, Width, Height)

; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
; So this will position our gui at (0,0) with the Width and Height specified earlier (half of the original image)
;UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, A_ScreenWidth, A_ScreenHeight)


; Select the object back into the hdc
SelectObject(hdc, obm)

; Now the bitmap may be deleted
DeleteObject(hbm)

; Also the device context related to the bitmap may be deleted
DeleteDC(hdc)

; The graphics may now be deleted
Gdip_DeleteGraphics(G)

; The bitmap we made from the image may be deleted
Gdip_DisposeImage(pBitmap)
}


See http://www.autohotkey.com/forum/viewtopic.php?t=57721 for the original post in General Chat.

Can anyone give me any advice?
Back to top
View user's profile Send private message Visit poster's website
closed



Joined: 07 Feb 2008
Posts: 509

PostPosted: Wed May 05, 2010 3:33 pm    Post subject: Reply with quote

Quote from the function last line:

Code:
; The bitmap we made from the image may be deleted
Gdip_DisposeImage(pBitmap)



so you cannot have it for a second show unless you recreate it or change your code.

quick and dirty code to try it out:

Code:
#SingleInstance, Force
#NoEnv
SetBatchLines, -1
counter=0
SetWorkingDir %A_ScriptDir%

gosub, StartGDI

Loop, %A_Scriptdir%\*.jpg
    FileList = %FileList%%A_LoopFileName%`n

Loop, parse, FileList, `n
{
 if A_LoopField =  ; Ignore the blank item at the end of the list.
  continue

pBitmap%A_Index% := Gdip_CreateBitmapFromFile(A_LoopField)
 sleep, 200
counter ++
}
loop 4
{
Loop, %counter%
{
pbitmap:=pBitmap%A_Index%
Gosub, showimage
Sleep, 250
}
}
Return




Showimage:
; Check to ensure we actually got a bitmap from the file, in case the file was corrupt or some other error occured
If !pBitmap
{
   MsgBox, 48, File loading error!, Could not load the image specified
   ExitApp
}

; Get the width and height of the bitmap we have just created from the file
; This will be the dimensions that the file is
Width := Gdip_GetImageWidth(pBitmap)
Height := Gdip_GetImageHeight(pBitmap)


; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
; We are creating this "canvas" at half the size of the actual image
; We are halving it because we want the image to show in a gui on the screen at half its dimensions
;hbm := CreateDIBSection(A_ScreenWidth, A_ScreenHeight)
hbm := CreateDIBSection(Width, Height)

; Get a device context compatible with the screen
hdc := CreateCompatibleDC()

; Select the bitmap into the device context
obm := SelectObject(hdc, hbm)

; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromHDC(hdc)

; We do not need SmoothingMode as we did in previous examples for drawing an image
; Instead we must set InterpolationMode. This specifies how a file will be resized (the quality of the resize)
; Interpolation mode has been set to HighQualityBicubic = 7
Gdip_SetInterpolationMode(G, 7)

; DrawImage will draw the bitmap we took from the file into the graphics of the bitmap we created
; We are wanting to draw the entire image, but at half its size
; Coordinates are therefore taken from (0,0) of the source bitmap and also into the destination bitmap
; The source height and width are specified, and also the destination width and height (half the original)
; Gdip_DrawImage(pGraphics, pBitmap, dx, dy, dw, dh, sx, sy, sw, sh, Matrix)
; d is for destination and s is for source. We will not talk about the matrix yet (this is for changing colours when drawing)
Gdip_DrawImage(G, pBitmap, 0, 0, Width, Height, 0, 0, Width, Height)

; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
; So this will position our gui at (0,0) with the Width and Height specified earlier (half of the original image)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width, Height)


; Select the object back into the hdc
SelectObject(hdc, obm)

; Now the bitmap may be deleted
DeleteObject(hbm)

; Also the device context related to the bitmap may be deleted
DeleteDC(hdc)

; The graphics may now be deleted
Gdip_DeleteGraphics(G)

return



StartGDI:
 If !pToken := Gdip_Startup()
 {
  MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
  ExitApp
 }
 OnExit, Exit
 ; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
 Gui, 1: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop

 ; Show the window
 Gui, 1: Show, NA

 ; Get a handle to this window we have created in order to update it later
 hwnd1 := WinExist()
Return

esc::
Exit:
Loop, %counter%
{
pbitmap:=pBitmap%A_Index%
Gdip_DisposeImage(pBitmap)
}
Gdip_Shutdown(pToken)
ExitApp
Return
Back to top
View user's profile Send private message
Murp|e



Joined: 12 Jan 2007
Posts: 531
Location: Norway

PostPosted: Wed May 05, 2010 10:00 pm    Post subject: Reply with quote

yume: That worked like a charm, thanks!
Back to top
View user's profile Send private message Visit poster's website
..:: Free Radical ::..



Joined: 20 Sep 2006
Posts: 72

PostPosted: Thu May 06, 2010 5:38 pm    Post subject: Reply with quote

many thanks for this awesome library tic.

A desktop widget example

Code:

#SingleInstance, Force
SetBatchLines, -1
listlines Off

If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}
OnExit, Exit

SetTimer Display, 1000
   
Display:

Gui, 1:  -Caption +E0x80000 +LastFound +OwnDialogs +Owner

Gui, 1: Show, NA, Widget

GoSub, SetBottom

hwnd1 := WinExist()

hbm := CreateDIBSection(Width, Height)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)

Width := A_ScreenWidth, Height := A_ScreenHeight
Spacing := 20
Area := (Width-Spacing)/Drives

DriveGet, HDD_List, List, Fixed
Drives := StrLen(HDD_List)

xpos := Spacing

;pBrush := Gdip_BrushCreateSolid(0x80000000)
pBrush := Gdip_CreateLineBrush(0, 0, 0, 114, 0xF0000000, 0x00000000, 1)
Gdip_FillRoundedRectangle(G, pBrush, -1, -1, Width+1, 115, 0)
Gdip_DeleteBrush(pBrush)

Loop, parse, HDD_List
{
   HDD := A_LoopField . ":"
   ypos := Spacing
   DriveGet, cap, capacity, % HDD
   DrivespaceFree, free, % HDD
   DriveGet, fs, fs, % HDD
   DriveGet, label, label, % HDD
   DriveGet, serial, serial, % HDD
   DriveGet, type, type, % HDD
   DriveGet, status, status, % HDD

   Percent := Round(((cap-free)*100/cap),1)

   Gdip_TextToGraphics(G, label . " (" . HDD . ") ", "x" . xpos . " y" . ypos . " Left cffffffff r4 s20 Bold", "Segoe UI", Width, Height)
   ypos += Spacing*1.3
   Gdip_TextToGraphics(G, Percent . " % full", "x" . xpos . " y" . ypos . " Left cffffffff r4 s16 Bold", "Segoe UI", Width, Height)
   ypos += Spacing*1.2
   If free > 1000
   Gdip_TextToGraphics(G, Round(free/1024,2) . " GB free of " . Round(cap/1024,2) . " GB", "x" . xpos . " y" . ypos . " Left cffffffff r4 s15", "Segoe UI SemiBold", Width, Height)
   else if cap > 1000
   Gdip_TextToGraphics(G, free . " MB free of " . Round(cap/1024,2) . " GB", "x" . xpos . " y" . ypos . " Left cffffffff r4 s15", "Segoe UI SemiBold", Width, Height)
   else Gdip_TextToGraphics(G, free . " MB free of " . cap . " MB", "x" . xpos . " y" . ypos . " Left cffffffff r4 s15", "Segoe UI SemiBold", Width, Height)

   xpos += Round(Area)
}
UpdateLayeredWindow(hwnd1, hdc, (A_ScreenWidth-Width)//2, (A_ScreenHeight-Height)//2, Width, Height)
OnMessage(0x201, "WM_LBUTTONDOWN")
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_DisposeImage(pBitmap)
Return

SetBottom:
If !Bottom
{
   WinGet, Prnt, ID, Program Manager
   WinGet, Chld, ID, Widget
   DllCall("SetParent", Int, Chld, Int, Prnt)
   Bottom = 1
}
return

WM_LBUTTONDOWN()
{
   PostMessage, 0xA1, 2
}

Exit:
Gdip_Shutdown(pToken)
ExitApp
Return
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3 ... 23, 24, 25 ... 60, 61, 62  Next
Page 24 of 62

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group