 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
AHKsimple
Joined: 27 Oct 2006 Posts: 14
|
Posted: Sun Oct 29, 2006 9:54 am Post subject: |
|
|
This is exactly what I've been looking for but I got an error.
"Error in GdipCreateBitmapFromFile (2: InvalidParameter) 0 (At GDIplus_LoadBitmap)"
 |
|
| Back to top |
|
 |
skwire
Joined: 18 Jan 2006 Posts: 132 Location: Conway, Arkansas
|
Posted: Sun Oct 29, 2006 4:15 pm Post subject: |
|
|
| 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 |
|
 |
JBensimon
Joined: 16 Nov 2004 Posts: 130 Location: New York
|
Posted: Thu Jan 11, 2007 10:25 am Post subject: |
|
|
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 |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Thu Jan 11, 2007 12:34 pm Post subject: |
|
|
| 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 |
|
 |
Idexmpls Guest
|
Posted: Tue Feb 06, 2007 10:50 pm Post subject: |
|
|
Skan, can GDImage.DLL be incorporated into AHK script? |
|
| Back to top |
|
 |
quatermass
Joined: 14 Dec 2005 Posts: 102
|
Posted: Wed Feb 21, 2007 5:45 pm Post subject: |
|
|
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 |
|
 |
Helpy Guest
|
Posted: Wed Feb 21, 2007 6:18 pm Post subject: |
|
|
| 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: 4
|
Posted: Thu Mar 01, 2007 11:48 pm Post subject: |
|
|
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 |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Fri Mar 02, 2007 11:06 am Post subject: |
|
|
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 |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1249
|
Posted: Fri Mar 02, 2007 12:36 pm Post subject: |
|
|
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 |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1249
|
Posted: Sat Mar 03, 2007 6:39 am Post subject: |
|
|
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 9:12 am; edited 1 time in total |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1249
|
Posted: Sat Mar 03, 2007 9:05 am Post subject: |
|
|
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 |
|
 |
JohnCritton
Joined: 01 Mar 2007 Posts: 4
|
Posted: Sat Mar 03, 2007 11:28 pm Post subject: |
|
|
| 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 |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1249
|
Posted: Sun Mar 04, 2007 12:46 am Post subject: |
|
|
| 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 |
|
 |
willyfoo
Joined: 03 Jun 2007 Posts: 25
|
Posted: Mon Jun 11, 2007 8:03 pm Post subject: |
|
|
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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|