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 

Image conversions and capturing with GDI+
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Fri Sep 15, 2006 4:04 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10465

PostPosted: Sun Sep 17, 2006 1:00 am    Post subject: Reply with quote

Very nice. There have definitely been requests for capturing only a portion of the screen.
Back to top
View user's profile Send private message Send e-mail
robiandi



Joined: 08 Aug 2006
Posts: 50

PostPosted: Sun Sep 17, 2006 8:59 am    Post subject: Reply with quote

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
View user's profile Send private message
Paulo [not logged]
Guest





PostPosted: Sat Sep 30, 2006 6:03 pm    Post subject: Reply with quote

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: 99
Location: Stuttgart, Germany

PostPosted: Sat Sep 30, 2006 8:58 pm    Post subject: Reply with quote

Splendid! Thanks PhiLho, holomind!
Back to top
View user's profile Send private message Visit poster's website
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Sun Oct 01, 2006 10:48 am    Post subject: Reply with quote

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 9:53 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Paulo [not logged]
Guest





PostPosted: Sun Oct 01, 2006 5:07 pm    Post subject: Reply with quote

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

PostPosted: Wed Oct 04, 2006 12:14 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Wed Oct 04, 2006 12:51 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 5594

PostPosted: Wed Oct 04, 2006 1:24 pm    Post subject: Reply with quote

Dear PhiLho, Smile

This might interest you ( in case you have not already visited )
http://www.zapsolution.com/winlift/gdimage.htm
GDImage.DLL (Windows 32 bit) is commerical, I downloaded and tried some .exe examples provided.

The examples were absolutely breath taking .. Shocked
The CHM help provided is excellent!

I guess the DLL (60KB) is a kind of wrapper built around GDI & GDIPLUS.
I installed it and have uploaded the contents as a .ZIP for you:
The ZIP : http://autohotkey.net/~goyyah/samples/GDImage.zip
Or take a glance at the documentation:
The CHM : http://autohotkey.net/~goyyah/samples/gdimage.chm

Regards, Smile
_________________
SKAN - Suresh Kumar A N
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5594

PostPosted: Sun Oct 15, 2006 5:10 pm    Post subject: Reply with quote

Dear PhiLho, Smile

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, Smile
_________________
SKAN - Suresh Kumar A N
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Mon Oct 16, 2006 9:08 am    Post subject: Reply with quote

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... Wink
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 5594

PostPosted: Mon Oct 16, 2006 9:43 am    Post subject: Reply with quote

PhiLho wrote:
But I welcome any contribution... Wink


Sure .. Very Happy

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, Smile
_________________
SKAN - Suresh Kumar A N
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Wed Oct 18, 2006 11:12 am    Post subject: Reply with quote

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... Smile
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 5:48 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
SKAN



Joined: 26 Dec 2005
Posts: 5594

PostPosted: Wed Oct 18, 2006 6:29 pm    Post subject: Reply with quote

Wow! Shocked .. Very Happy
I have to take a deep look .. Will try it & post again!

Many Thanks Very Happy
_________________
SKAN - Suresh Kumar A N
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6, 7  Next
Page 2 of 7

 
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