 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Carcophan
Joined: 24 Dec 2008 Posts: 1308 Location: :noitacoL
|
Posted: Thu Feb 18, 2010 8:35 pm Post subject: Screenshoted/BMP image of a gui changes colors |
|
|
Do not know if this is a bug, or intended feature, or maybe I am just crazy...
I took a screenshot of a GUI/Graph that I am working with.
I assume people may need some information about the graph, so I made a BMP image with the GUI/graph image inside with some text/edits to highlight key points.
Test code to display the BMP image itself:
| Code: |
;===================================================================
;I attempted to upload to AHK.net but it is blocked from work.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance Force
;===================================================================
Gui +Resize
Gui, Add, Button, x5 y5 gHelpGDI, Help Info
Gui, show, w100 h100, Test GDI+ color bug
return
;===================================================================
HelpGDI:
Gui, 2:+owner1 +resize ; Make the main window (Gui #1) the owner of the "about box" (Gui #2).=
;Gui +Disabled ; Disable main window.
Gui, 2:Color, ffffaa
Gui, 2:Add, Picture, , test img.bmp
Gui, 2:Show, w375 h700, GDI+ HELP
return
;===================================================================
kill:
GuiClose:
GuiEscape:
ExitApp
;===================================================================
2GuiClose:
2GuiEscape:
Gui, 2:Destroy
return
;===================================================================
|
If you want to test it, you need to take a screenshot of a GUI. (assuming any standard grey gui). Save the image as a bmp, and store it in the library with the script.
If you test it, you will see that the BMP image itself, which should remain grey (and is grey if you just open the image itself, as opposed to launching it with the script) changes colors. |
|
| Back to top |
|
 |
Carcophan
Joined: 24 Dec 2008 Posts: 1308 Location: :noitacoL
|
|
| Back to top |
|
 |
Leef_me
Joined: 08 Apr 2009 Posts: 5333 Location: San Diego, California
|
Posted: Sun Feb 21, 2010 7:01 am Post subject: |
|
|
I see the same thing if a color in the image is 0xf0f0f0.
I used mousegetpos & pixelgetcolor to get the original color of your test image and then tweaked my test image to have a portion of it be that same 0xf0f0f0 color, the background of the gui as well as the portion of the image both turned the same color.
I can't confirm but I believe it might be related to the 'default' color of gui controls. Namely the ahk assembly code saying "hey wait a minute, that is the same color as what a control should be, but the color of controls has been changed, therefore I must change this color to match."
Seems like a bug to me. (one ahker's opinion)  |
|
| Back to top |
|
 |
Guest
|
Posted: Sun Feb 21, 2010 10:38 am Post subject: Re: Screenshoted/BMP image of a gui changes colors |
|
|
BUG CONFIRMED - XP SP1
I was about to post not confirmed, cuz running your exact test script did not exhibit that behavior, but then I made my own screenshot...& got the buggy behavior...the "magic" color in my case is 0xECD8E9 (RGB)...
Steps to reproduce...
- Download Test Script: GDI test.ahk (don't need imgs)
- Make a screenshot of 1st Gui in bmp & png formats
- Run test script
- On the 1st Gui press Alt+Print Screen to take a window-only screenshot
- Open MSPaint or some image program & paste the screenshot
- Save that screenshot in the scripts dir as testimg.bmp & testimg.png
- Close test script
- Edit test script to point to the bmp version of the test img
- Find the line: Gui, 2:Add, Picture, , testGDI.bmp
- Change it to: Gui, 2:Add, Picture, , testimg.bmp
- Run test script again & click button...2nd Gui's Picture control should (incorrectly) have the same bgcolor as set on 2nd Gui...
- Edit test script to use png version & try again, see png version works correctly
- Edit test script back to the bmp version
- Add AltSubmit to the Picture control's options, now the bmp version works correctly
...I don't know what causes it, but it's definitely a bug...(but it's a bug with 2 workarounds...1) use png, not bmp...2) use AltSubmit... |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 7293 Location: Australia
|
Posted: Sun Feb 21, 2010 12:59 pm Post subject: |
|
|
Interesting. However,
| Carcophan wrote: | | Test GDI+ color bug | ... it's not GDI+. As Guest pointed out, it doesn't happen if you use AltSubmit. AltSubmit tells it to use GDI+. Using a PNG would have the same effect, since GDI+ is required to load it.
The inner workings of Gui,Color are very simple: when the colour is changed, create a solid brush of the new colour; when a WM_ERASEBKGND message is received, call FillRect using the background brush. It doesn't do much else.
Given that loading the image manually as below exhibits the same problem, I would rule out AutoHotkey's image-loading routine as the cause:
| Code: | SS_BITMAP := 14 ; Required for it to show a bitmap.
STM_SETIMAGE := 0x172 ; Message used to set bitmap.
IMAGE_BITMAP := 0 ; Type of image.
LR_LOADFROMFILE := 0x10 ; Required flag to load from file.
LR_CREATEDIBSECTION := 0x2000 ; Optional flag, used by AHK but makes no difference.
; Add the Picture control with the appropriate style. Note that a "Text" control is
; exactly the same in this context: both are really a Windows "Static" control.
Gui, 2:Add, Picture, hwndhpic +%SS_BITMAP%
; Load the image with a basic GDI call.
hbmp := DllCall("LoadImage", "uint", 0, "str", "test img.bmp", "uint", IMAGE_BITMAP, "int", 0, "int", 0, "uint", LR_LOADFROMFILE|LR_CREATEDIBSECTION)
; Set the image.
SendMessage, STM_SETIMAGE, IMAGE_BITMAP, hbmp,, ahk_id %hpic%
| Actually, this is more or less the same as what AutoHotkey does by default (and what I imagine the majority of GDI-based applications would do). As you can see, it only sets the image; actually drawing the image is up to Windows.
It seems vaguely familiar to me, like an obscure Windows "feature". I found that resizing the image put the colour off slightly (f0f0f0 -> efefef) and that prevented it from changing colour. However, if the image was loaded by GDI+, the colour remained f0f0f0.
If I had more time, I'd complete the test: create a Static control via CreateWindowEx, load and set the image as above, and handle WM_ERASEBKGND in script. I suspect it would have the same issue. |
|
| 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
|