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, 8  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
AHKsimple



Joined: 27 Oct 2006
Posts: 14

PostPosted: Sun Oct 29, 2006 8:54 am    Post subject: Reply with quote

This is exactly what I've been looking for but I got an error.

"Error in GdipCreateBitmapFromFile (2: InvalidParameter) 0 (At GDIplus_LoadBitmap)"

Question
Back to top
View user's profile Send private message
skwire



Joined: 18 Jan 2006
Posts: 273
Location: Conway, Arkansas

PostPosted: Sun Oct 29, 2006 3:15 pm    Post subject: Reply with quote

If you're running the test script as it is, you will need to create a bitmap file in the same directory as the script named: OriginalImage.bmp
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
JBensimon



Joined: 16 Nov 2004
Posts: 153
Location: New York

PostPosted: Thu Jan 11, 2007 9:25 am    Post subject: Reply with quote

Well, PhiLho, I finally got around to testing the functions in your GDIplusWrapper.ahk, and they work as advertised. Great stuff!

Can I assume that the set of GDI+ functions you've wrapped (and their allowed parameters) don't depend on any particular version of GDIplus.dll?

On my test system, WinXP SP2, the version loaded by default when I tested was 5.1.x and was one of two versions stored in the Side-by-Side assembly store, %SystemRoot%\WinSxS\..., the more recent one and presumably the default. Several other versions, however, exist in various application folders, including a couple of Adobe apps (they were older) and, most notably, a version 6.0.x in the Office 2003 folder, though none are in the system %PATH%. I'm just trying to gauge the extent to which an AHK app that uses GDI+ via your functions will be compatible across a wide range of machine (on some of which other SxS versions may have been installed by different apps, maybe even made the default). If versions are a problem, I think a properly formatted .config file can be placed in the same folder to specify a desired version, or Resource Hacker could be used to supplement the config file already stored as a resource in AutoHotkeySC.bin (it currently just specifies version 6.x of comctl32).

Jacques.
Back to top
View user's profile Send private message Visit poster's website
PhiLho



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

PostPosted: Thu Jan 11, 2007 11:34 am    Post subject: Reply with quote

JBensimon wrote:
Can I assume that the set of GDI+ functions you've wrapped (and their allowed parameters) don't depend on any particular version of GDIplus.dll?
Frankly, I don't know, but I will answer yes. I didn't saw version-specific info in the API found in MSDN.
_________________
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
Idexmpls
Guest





PostPosted: Tue Feb 06, 2007 9:50 pm    Post subject: Reply with quote

Skan wrote:
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, can GDImage.DLL be incorporated into AHK script?
Back to top
quatermass



Joined: 14 Dec 2005
Posts: 216

PostPosted: Wed Feb 21, 2007 4:45 pm    Post subject: Reply with quote

I'm looking for a way to record the current displayed desktop background in Windows 2000/XP.

Change it for my own image.

Then put the original image back.

Now I know I can record the current user registry settings

Code:
RegRead, Original_TileWallpaper, HKEY_CURRENT_USER, Control Panel\Desktop, TileWallpaper
RegRead, Original_WallpaperStyle, HKEY_CURRENT_USER, Control Panel\Desktop, WallpaperStyle


and alter them.

But how do force Windows to re-read these new registry settings and refresh the background?


Would the ahk GDI library be able to do this?
_________________
Stuart Halliday
Back to top
View user's profile Send private message Visit poster's website
Helpy
Guest





PostPosted: Wed Feb 21, 2007 5:18 pm    Post subject: Reply with quote

quatermass wrote:
Would the ahk GDI library be able to do this?
No, this is totally unrelated.
Search the forum in this section, you will find scripts to change the background.
Back to top
JohnCritton



Joined: 01 Mar 2007
Posts: 14

PostPosted: Thu Mar 01, 2007 10:48 pm    Post subject: Reply with quote

Thanks for your really great work. I'm using it to capture parts of a window and save it as picture.
However, I would like to rotate and/or flipp the Image. I found something promissing in your warper script that might do the job:

; For a JPEG image, specifies lossless 90-degree clockwise rotation.
#EncoderValueTransformRotate90 = 13
; For a JPEG image, specifies lossless 180-degree rotation.
#EncoderValueTransformRotate180 = 14
; For a JPEG image, specifies lossless 270-degree clockwise rotation.
#EncoderValueTransformRotate270 = 15
; For a JPEG image, specifies a lossless horizontal flip.
#EncoderValueTransformFlipHorizontal = 16
; For a JPEG image, specifies a lossless vertical flip.
#EncoderValueTransformFlipVertical = 17

Unfortunatelly I'm too stuipid to figure out how to use those Encoder Values.
Could you provide a small sample script on how to use them? That would help a lot.

Thanks in advance.

-John
Back to top
View user's profile Send private message
PhiLho



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

PostPosted: Fri Mar 02, 2007 10:06 am    Post subject: Reply with quote

I am sorry, but I have not explored GDI+ image transformations yet, and don't plan to do it soon, due to lack of time and other projects. If somebody else is willing to do this, (s)he is welcome.
_________________
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
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Fri Mar 02, 2007 11:36 am    Post subject: Reply with quote

I have a script doing the transformation, but unfortunately not in AHK. I only sketched the needed procedure here, so, you have to adjust it appropriately.

BTW, it just re-used the returned structure by the system. It may not be a good idea, however.

Code:

DllCall("gdiplus\GdipGetEncoderParameterListSize", "Uint", pImage, "Uint", pCodec, "UintP", nSize)
VarSetCapacity(pi, nSize)
DllCall("gdiplus\GdipGetEncoderParameterList", "Uint", pImage, "Uint", pCodec, "Uint", nSize, "Uint", &pi)

nValue := 14 ; JPEG Transformation: 13 14 15 16 17

EncodeInteger(&pi +  0, 1)                     ; number of list
; 4 - 20                                     ; 16 byte CLSID of Encoder
EncodeInteger(&pi + 20, 1)                     ; number of values
;EncodeInteger(&pi + 24, 4)                     ; type of values
EncodeInteger(&pi + 28, DecodeInteger(&pi + 28) + 4 * (nValue - 13))      ; address of the value

pParam := &pi

DllCall("gdiplus\GdipSaveImageToFile", "Uint", pImage, "Uint", &wFileTo, "Uint", pCodec, "Uint", pParam)


DecodeInteger(ptr)
{
   Return *ptr | *++ptr << 8 | *++ptr << 16 | *++ptr << 24
}

EncodeInteger(ref, val)
{
   DllCall("ntdll\RtlFillMemoryUlong", "Uint", ref, "Uint", 4, "Uint", val)
}

Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Sat Mar 03, 2007 5:39 am    Post subject: Reply with quote

Here are GUIDs I found so far which are used in GdiPlus.

Code:

ImageFormatUndefined := "{B96B3CA9-0728-11D3-9D7B-0000F81EF32E}"
ImageFormatMemoryBMP := "{B96B3CAA-0728-11D3-9D7B-0000F81EF32E}"
ImageFormatBMP       := "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}"
ImageFormatEMF       := "{B96B3CAC-0728-11D3-9D7B-0000F81EF32E}"
ImageFormatWMF       := "{B96B3CAD-0728-11D3-9D7B-0000F81EF32E}"
ImageFormatJPEG      := "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
ImageFormatPNG       := "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}"
ImageFormatGIF       := "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}"
ImageFormatTIFF      := "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}"
ImageFormatEXIF      := "{B96B3CB2-0728-11D3-9D7B-0000F81EF32E}"
ImageFormatIcon      := "{B96B3CB5-0728-11D3-9D7B-0000F81EF32E}"

ImageCodecBMP        := "{557CF400-1A04-11D3-9A73-0000F81EF32E}"
ImageCodecJPEG       := "{557CF401-1A04-11D3-9A73-0000F81EF32E}"
ImageCodecGIF        := "{557CF402-1A04-11D3-9A73-0000F81EF32E}"
ImageCodecEMF        := "{557CF403-1A04-11D3-9A73-0000F81EF32E}"
ImageCodecWMF        := "{557CF404-1A04-11D3-9A73-0000F81EF32E}"
ImageCodecTIFF       := "{557CF405-1A04-11D3-9A73-0000F81EF32E}"
ImageCodecPNG        := "{557CF406-1A04-11D3-9A73-0000F81EF32E}"
ImageCodecIcon       := "{557CF407-1A04-11D3-9A73-0000F81EF32E}"

EncoderTransformation   := "{8D0EB2D1-A58E-4EA8-AA14-108074B7B6F9}"
EncoderQuality          := "{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}"
EncoderLuminanceTable   := "{EDB33BCE-0266-4A77-B904-27216099E717}"
EncoderChrominanceTable := "{F2E455DC-09B3-4316-8260-676ADA32481C}"
EncoderCompression      := "{E09D739D-CCD4-44EE-8EBA-3FBF8BE4FC58}"
EncoderColorDepth       := "{66087055-AD66-4C7C-9A18-38A2310B8337}"
EncoderSaveFlag         := "{292266FC-AC40-47BF-8CFC-A85B89A655DE}"
EncoderVersion          := "{24D18C76-814A-41A4-BF53-1C219CCCF797}"
EncoderScanMethod       := "{3A4E2661-3109-4E56-8536-42C156E7DCFA}"
EncoderRenderMethod     := "{6D42C53A-229A-4825-8BB7-5C99E2B9A8B8}"



Last edited by Sean on Sat Mar 03, 2007 8:12 am; edited 1 time in total
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Sat Mar 03, 2007 8:05 am    Post subject: Reply with quote

OK, I converted the script to AHK. It'll work only with JPEG files. Adopting it to TIFF should be easy. Other formats produced no available parameter list in my test. And, it incorporates only two parameter types, Transformation and Quality, although there exist two more for JPEG, LuminanceTable and ChrominanceTable.

It requires CoHelper.ahk which can be saved here:
http://www.autohotkey.com/forum/topic16631.html

Code:

#NoEnv
#Include CoHelper.ahk

sFileFr := "C:\ImageFr.jpg"   ; Adjust the name
sFileTo := "C:\ImageTo.jpg"   ; Adjust the name

SplitPath, sFileFr, , , sExtFr
SplitPath, sFileTo, , , sExtTo

If (sExtFr <> "JPG") || (sExtTo <> "JPG")
{
   MsgBox % "Both Files must be of JPG! Now Exit the App."
   ExitApp
}

hModule := DllCall("LoadLibrary", "str", "gdiplus.dll")

VarSetCapacity(si, 16, 0)
si := Chr(1)

DllCall("gdiplus\GdiplusStartup", "UintP", pToken, "Uint", &si, "Uint", 0)

DllCall("gdiplus\GdipGetImageEncodersSize", "UintP", nCount, "UintP", nSize)
VarSetCapacity(ci, nSize)
DllCall("gdiplus\GdipGetImageEncoders", "Uint", nCount, "Uint", nSize, "Uint", &ci)

Loop, %nCount%
{
   pTypes := DecodeInteger(&ci + 76 * (A_Index - 1) + 44)
   Unicode2Ansi(pTypes, sTypes)
   If InStr(sTypes, "." . sExtTo)
   {
      pCodec := &ci + 76 * (A_Index - 1)
      Break
   }
}

If !pCodec
   ExitApp

Ansi2Unicode(sFileFr, wFileFr)
Ansi2Unicode(sFileTo, wFileTo)

DllCall("gdiplus\GdipLoadImageFromFile", "str", wFileFr, "UintP", pImage)

DllCall("gdiplus\GdipGetEncoderParameterListSize", "Uint", pImage, "Uint", pCodec, "UintP", nSize)
VarSetCapacity(pi, nSize)
DllCall("gdiplus\GdipGetEncoderParameterList", "Uint", pImage, "Uint", pCodec, "Uint", nSize, "Uint", &pi)

nValue := 14                        ; JPEG Transformation: 13 14 15 16 17
EncodeInteger(&pi +  0, 1)                  ; number of list
;4 - 20                           ; 16 byte CLSID of Encoder
EncodeInteger(&pi + 20, 1)                  ; number of values
EncodeInteger(&pi + 24, 4)                  ; type of values
EncodeInteger(DecodeInteger(&pi + 28), nValue)            ; address of the value
pParam := &pi

/*
nValue := 90                        ; JPEG Quality: 0 - 100
EncodeInteger(&pi + 28, 1)                  ; number of list
;32 - 48                        ; 16 byte CLSID of Encoder
EncodeInteger(&pi + 48, 1)                  ; number of values
EncodeInteger(&pi + 52, 4)                  ; type of values
EncodeInteger(DecodeInteger(&pi + 56), nValue)            ; address of the value
pParam := &pi + 28
*/

DllCall("gdiplus\GdipSaveImageToFile", "Uint", pImage, "Uint", &wFileTo, "Uint", pCodec, "Uint", pParam)

DllCall("gdiplus\GdipDisposeImage", "Uint", pImage)
DllCall("gdiplus\GdiplusShutdown" , "Uint", pToken)
DllCall("FreeLibrary", "Uint", hModule)

Back to top
View user's profile Send private message
JohnCritton



Joined: 01 Mar 2007
Posts: 14

PostPosted: Sat Mar 03, 2007 10:28 pm    Post subject: Reply with quote

Sean wrote:
OK, I converted the script to AHK. It'll work only with JPEG files.

Thanks a lot!
But how do I enable the JPEG Quality settings? If I activate the part that is commented out in your script, the rotation is no longer working.
What I'm doing wrong?

-John
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Sat Mar 03, 2007 11:46 pm    Post subject: Reply with quote

JohnCritton wrote:
But how do I enable the JPEG Quality settings? If I activate the part that is commented out in your script, the rotation is no longer working.

I think you have to apply them separately, because of the difference of their nature.
I reckoned it would work to combine them as the adjacent blocks and set the number of list to 2. But, it didn't work. It may be because Transformation is a lossless operation (:so, only work from JPEG to JPEG) whereas Quality is a lossy operation (:so, works from ANY FORMAT to JPEG).
Back to top
View user's profile Send private message
willyfoo



Joined: 03 Jun 2007
Posts: 29

PostPosted: Mon Jun 11, 2007 7:03 pm    Post subject: Reply with quote

Surprised nobody really brought this up yet given that digtal cameras are abundant now and store exif information which states the orientation.

I just need to display the jpg file in it's correct orientation resized to fit a window.

So it needs to
Load jpg
Get w,h,exif orientation
rotate if necessary
calculate w if h is sized to windowheight
calculate h if w is sized to windowwidth
determine show mode (fit or crop)
show appropriate dimension based on mode

Any idea how best to implement this?? I think this is useful enough to be implemented into the ahk library when done
_________________
http://willyfoo.com
http://livestudios.sg
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, 4, 5, 6, 7, 8  Next
Page 3 of 8

 
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