 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Fri Sep 15, 2006 3:04 pm Post subject: |
|
|
I updated the library to have a new function: GDIplus_CaptureScreenRectangle
Requested in Screenshot of a little part of the screen, thanks for idea, and thanks holomind for the starting point. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10716
|
Posted: Sun Sep 17, 2006 12:00 am Post subject: |
|
|
| Very nice. There have definitely been requests for capturing only a portion of the screen. |
|
| Back to top |
|
 |
robiandi
Joined: 08 Aug 2006 Posts: 49
|
Posted: Sun Sep 17, 2006 7:59 am Post subject: |
|
|
| I am very interested to have the possibilty to capture only a portion of the screen and was eagerly waiting for it. |
|
| Back to top |
|
 |
Paulo [not logged] Guest
|
Posted: Sat Sep 30, 2006 5:03 pm Post subject: |
|
|
Hello, PhiLho.
Very usefull image functions!Thanks for your work.
May I suggest the inclusion of the "GdipDisposeImage(GpImage *image)" function to release the image so we can use|delete|overwrite it? |
|
| Back to top |
|
 |
olfen
Joined: 04 Jun 2005 Posts: 113 Location: Stuttgart, Germany
|
Posted: Sat Sep 30, 2006 7:58 pm Post subject: |
|
|
| Splendid! Thanks PhiLho, holomind! |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Sun Oct 01, 2006 9:48 am Post subject: |
|
|
| Paulo [not logged] wrote: | | May I suggest the inclusion of the "GdipDisposeImage(GpImage *image)" function to release the image so we can use|delete|overwrite it? | Good idea! I neglected the functions to free memory, partly because I don't know well the API (whose flat API is badly documented), partly because these functions were made mostly for a one-shot use, but people will start to use them in permanently running scripts, so freeing memory will be necessary.
I will add this soon. Do you see other places in my functions where I should manage / free the memory? _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Last edited by PhiLho on Mon Oct 02, 2006 8:53 am; edited 1 time in total |
|
| Back to top |
|
 |
Paulo [not logged] Guest
|
Posted: Sun Oct 01, 2006 4:07 pm Post subject: |
|
|
| PhiLho wrote: | | ...Do you see other places in my functions where I should manage / free the memory? |
Your functions seem perfect, I just mentioned "GdipDisposeImage" because (as you wrote) I am using your wrapper in a "non-one-shot" script.
Thanks,again. |
|
| Back to top |
|
 |
Landvermesser
Joined: 03 Nov 2004 Posts: 51
|
Posted: Wed Oct 04, 2006 11:14 am Post subject: |
|
|
How to resample/resize PNG picture with alpha-transparency using this technology? And may be convert ICO to PNG? _________________ My AHK project: http://landvermesser.tripod.com/ |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Wed Oct 04, 2006 11:51 am Post subject: |
|
|
Good questions, I think GDI+ can do that, but it needs some research... I won't do that right now. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Sun Oct 15, 2006 4:10 pm Post subject: |
|
|
Dear PhiLho,
I am taking a dive into GDIplusWrapper.ahk today ..
.. and I think it would help newbies if you could post seperate and simple
examples for every feature instead of one long TestGDIPlus.ahk
Just a suggestion.. Thanks for writing the wonderful code.
Regards,  _________________ URLGet - Internet Explorer based Downloader |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Mon Oct 16, 2006 8:08 am Post subject: |
|
|
Well, the TestGDIplus.ahk isn't so big, and I separated the various features with comments and/or labels...
It could be cleaner, but that's more a quick test code than a tutorial that I don't have much time to do.
But I welcome any contribution...  _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Mon Oct 16, 2006 8:43 am Post subject: |
|
|
| PhiLho wrote: | But I welcome any contribution...  |
Sure ..
I will try to make simple examples for posting in ask-for-help.
I wanted to demonstrate ( Carlol topic Timer on MsgBox? ) displaying
clipboard image data on a GUI.
Right now I am writing the image to disk and then displaying it.
Is there a way to directly display hBitmap ( or whatever! ) as a picture control?
Regards,  _________________ URLGet - Internet Explorer based Downloader |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Wed Oct 18, 2006 10:12 am Post subject: |
|
|
No need for GDI+ here.
That's the opportunity to test the famous STM_SETIMAGE as pointed out by Chris in http://www.autohotkey.com/forum/viewtopic.php?t=10091
As you can see, I reused your own GUI...
| Code: | appTitle = Show Graphic Clipboard
STM_SETIMAGE = 0x0172
IMAGE_BITMAP = 0
GMEM_MOVEABLE = 2
guiWidth = 400
guiHeight = 300
titleBarHeight = 24
clientHeight := guiHeight - titleBarHeight
Gui -Caption +Border
Gui Add, Picture, x0 y%titleBarHeight% vimage gChangeImage, KM64.png
Gui Font, s9 Bold, Tahoma
Gui Margin, 0, 0
Gui Add, Text, x0 y0 w%GuiWidth% h%titleBarHeight% +0x4 ; SS_BLACKRECT
Gui Add, Text, x0 y0 w%GuiWidth% h%titleBarHeight% cFFFFFF Backgroundtrans +0x200 gGuiMove
, %A_Space%%A_Space%%appTitle% ; SS_CENTERIMAGE?
Gui Show, w%guiWidth% h%guiHeight%, %appTitle%
Gui +LastFound
Return
GuiMove:
PostMessage 0xA1, 2, , , A ; WM_NCLBUTTONDOWN
Return
ChangeImage:
If (DllCall("IsClipboardFormatAvailable", "UInt", 2) = 0)
{
MsgBox 16, %appTitle%, No Bitmap Available
Return
}
r := DllCall("OpenClipboard", "UInt", 0)
If (r = 0)
{
MsgBox 16, %appTitle%, OpenClipboard
Return
}
hBitmap := DllCall("GetClipboardData"
, "UInt", 2) ; CF_BITMAP = 2, CF_DIB = 8
If (r = 0)
{
MsgBox 16, %appTitle%, GetClipboardData
Goto ClipboardCleanUp
}
If (hBitmap = 0)
{
MsgBox 16, %appTitle%, No Bitmap
Goto ClipboardCleanUp
}
; Make a copy of this data, because the handle points to data that will disappear on CloseClipboard
r := DllCall("CopyImage"
, "UInt", hBitmap
, "UInt", IMAGE_BITMAP
, "Int", 0, "Int", 0 ; Keep same dimensions
, "UInt", 0) ; No special flag
If (r = 0)
{
MsgBox 16, %appTitle%, CopyImage
Goto ClipboardCleanUp
}
hBitmap := r
ReplacePictureImage("Static1", hBitmap)
ClipboardCleanUp:
DllCall("CloseClipboard")
Return
GuiEscape:
ExitApp
; Given a Picture control (_pictureTitle),
; and a bitmap handle (from clipboard, from GDI operations, etc.),
; tell the Picture to change its image.
; Better than BitBlt, because we don't have to manage WM_PAINT...
; Note that the given _hBitmap no longer belongs to the caller,
; either the Picture owns it, or it is destroyed, for consistent behavior.
ReplacePictureImage(_pictureTitle, _hBitmap)
{
local hOldBitmap, hCurrentBitmap
; From info taken from http://www.autohotkey.com/forum/viewtopic.php?t=10091
; and from the source (in script_gui.cpp).
; Reset the image of the control before deleting it
SendMessage STM_SETIMAGE, IMAGE_BITMAP, 0, %_pictureTitle%
; Handle on the previous bitmamp
hOldBitmap := ErrorLevel
If (hOldBitmap != "FAIL" and hOldBitmap > 0)
; Destroy it
DllCall("DeleteObject", "UInt", hOldBitmap)
; Set new image
SendMessage STM_SETIMAGE, IMAGE_BITMAP, _hBitmap, %_pictureTitle%
; Get the handle on the bitmap stored by the control
SendMessage STM_GETIMAGE, IMAGE_BITMAP, 0, %_pictureTitle%
hCurrentBitmap := ErrorLevel
; If it is different than the sent one, XP made a copy because image has alpha transparency
If (hCurrentBitmap != "FAIL" and hCurrentBitmap != _hBitmap)
; So delete the sent image, to avoid a memory leak
DllCall("DeleteObject", "UInt", _hBitmap)
}
| I had a hard time to find how to copy the data in the bitmap from the clipboard. Most examples I saw on the Net merely copy Microsoft examples, BitBlting it to the screen... I started to use a convoluted method, when I found that CopyImage existed...
Using GDI is basically quite simple, it worked in my first attempt where I just use STM_SETIMAGE with the hBitmap directly taken from the clipboard, but it would have seriously leaked memory and GDI resources... Correctly releasing created data is the difficult part of this API.
I encapsulated the core functionnality in a function, for easy reuse. _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Last edited by PhiLho on Sun Oct 29, 2006 4:48 pm; edited 1 time in total |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Wed Oct 18, 2006 5:29 pm Post subject: |
|
|
Wow! ..
I have to take a deep look .. Will try it & post again!
Many Thanks  _________________ URLGet - Internet Explorer based Downloader |
|
| 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
|