nago Posted July 31, 2008 Share Posted July 31, 2008 (edited) Hi, This is a bit of a weird one but here goes. I've got a handful of images used for theming/skinning in some other application and the idea here is I want to make a "preview" program to display the finished product, so to speak, to make skinning for this other application easier. My problem is, one of the skinning files uses a combination of 6 icons into one BMP, so in order to display it correctly, I'd need to "break up" these file into six pieces. It's a 128x192 pixel bitmap with six 64x64 'zones' in it, arranged in a 2wx3h pattern. The zones are as follows: #1: 00,000;063,000;00,063;063,063 #2: 64,000;127,000;64,063;127,063 #3: 00,064;063,064;00,127;063,127 #4: 64,064;127,064;64,127;127,127 #5: 00,128;063,128;00,191;063,191 #6: 64,128;127,128;64,191;127,191 Is there: (1) A method to display only a certain portion of an image inside an image control in AutoIt if you know the exact coordinates within the image you wish to display? or (2) A method to crop images from AutoIt (perhaps via UDF) so I can chop up the image myself and display them normally? Any help is appreciated! -John Edited July 31, 2008 by nago Link to comment Share on other sites More sharing options...
monoceres Posted July 31, 2008 Share Posted July 31, 2008 (edited) Hi!The answer is GDI+, I made a little example for you #include <GDIPlus.au3> #include <windowsconstants.au3> $hwnd=GUICreate("Test!",550,320) GUISetSTate() _GDIPlus_Startup() $graphics=_GDIPlus_GraphicsCreateFromHWND($hwnd) $image=_GDIPlus_ImageLoadFromFile("test.jpg") draw() GUIRegisterMsg($WM_PAINT,"draw") Do $msg=GUIGetMsg() Until $msg=-3 _GDIPlus_ImageDispose($image) _GDIPlus_GraphicsDispose($graphics) _GDIPlus_Shutdown() Func draw() _GDIPlus_GraphicsDrawImageRectRect($graphics,$image,0,0,256,288,10,10,256,288) _GDIPlus_GraphicsDrawImageRectRect($graphics,$image,256,0,256,288,276,10,256,288) EndFuncAnd here's the image I tested it on (rename it as test.jpg): You should read the documentation for _GDIPlus_GraphicsDrawImageRectRect() so you can understand the example Edited July 31, 2008 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
nago Posted July 31, 2008 Author Share Posted July 31, 2008 (edited) Edit: This post wasn't very clear. See post below. Edited July 31, 2008 by nago Link to comment Share on other sites More sharing options...
rasim Posted July 31, 2008 Share Posted July 31, 2008 nagoCan I draw to specific controls?Yep, but will appear problem with control redrawing (painting), of course to avoid this behaviour you can subclassing control, but i think such solution not is necessary. If you want to create painted square, just use A Label control, or GuiCtrlCreateGraphic() func. Link to comment Share on other sites More sharing options...
nago Posted July 31, 2008 Author Share Posted July 31, 2008 (edited) I am not sure I understand how to do what you've said, so let me try to clarify myself a little:1) I want to draw a picture, normally using the GuiCtrlCreatePic() function, inside of an autoit created GUI. The image I am using here is a regular bitmap. I am not necessarily hung up on using GuiCtrlCreatePic, but if I didn't have more specific criteria below, this is probably the one I'd normally use.2) At specific parts overlaying this picture, I'd like to have three boxes. (To depart from my abstract: The picture is a background and the three boxes will represent where icons belong.)3) Each of these three boxes needs to be filled with a sub-section of one physical file. This is why I was looking into the _GDIPlus_GraphicsDrawImageRectRect() Function, to allow me to use one bitmap as six different images. The format of this bitmap is not under my control and therefore this criteria cannot be worked around or changed.4) The reason I want to make separate controls for the little boxes is because I want to be able to tell when they are moused over, so I can change the picture inside of them. This means that three of the six images contained in the bitmap are for regular display, and the other three are for mouse-overs.The files that contains the icons is split up like this:Each zone is 64x64. The Upper-Left pixel for each zone is:#1 00,00#2 00,64#3 64,00#4 64,64#5 00,128#6 64,128So given a background image that is 256x192, and the icon offsets as follows:#1 16,64#2 96,64#3 176,64will result in the desired output, which is as follows:Keeping in mind I would like to be able to measure mouseovers for each of these boxes, and these boxes should always be on top of that background. Edited July 31, 2008 by nago Link to comment Share on other sites More sharing options...
monoceres Posted July 31, 2008 Share Posted July 31, 2008 You can still use GDI+, just create empty pic controls and draw everything over them. When you have intercepted mouse overs, just draw another picture over it, and when mouse has left the area, just redraw the original picture. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
nago Posted July 31, 2008 Author Share Posted July 31, 2008 I see, so you're suggesting to create empty controls so I can get the mouse information, but then still just use the offset from the main window anyway? Is that right?The other issue I was seeming to have is that it draws correctly initially, but if you hide the window and then bring it back, the re-painting puts the sub-images behind the background. What's up with that, and can it be remidied? Link to comment Share on other sites More sharing options...
monoceres Posted July 31, 2008 Share Posted July 31, 2008 I see, so you're suggesting to create empty controls so I can get the mouse information, but then still just use the offset from the main window anyway? Is that right?The other issue I was seeming to have is that it draws correctly initially, but if you hide the window and then bring it back, the re-painting puts the sub-images behind the background. What's up with that, and can it be remidied?Yes, remember that autoit never has any idea that you have drawn to the window. You alone are responsible for it's appearance once you fiddling with GDI+.I forget to add Return "GUI_RUNDEFMSG" in the drawing func, but I don't know if that's the problem. Could you please post some (small) code that reproduce it? Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now