AutoHotkey Community

It is currently May 27th, 2012, 6:16 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1000 posts ]  Go to page Previous  1 ... 34, 35, 36, 37, 38, 39, 40 ... 67  Next
Author Message
 Post subject:
PostPosted: November 9th, 2010, 6:10 am 
but if you do decide to include it, maybe not wrap it all into one func, but rahter have

Gdip_BitmapFromHWND()
Gdip_BitmapFromMinimizedHWND()

just blabbering


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2010, 10:42 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
guest3456 wrote:
PrintWindow doesn't work on minimized windows (net searches will lead people to this same conclusion thats asked numerous times), so your library would become a wrapper+extension rather than just a wrapper.


I have decided not to include it,especially as its not 100% reliable, but I dont think the gdi+ library is just a wrapper. I mean Gdip_TextToGraphics() is hardly a wrapper :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2010, 10:56 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Quote:
I have decided not to include it
Thats probably for the best. Might be good to post it in the voodoo thread.
Quote:
I dont think the gdi+ library is just a wrapper
I agree.

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2010, 12:04 am 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
I have a question that I have wondered about for a while.
How do you draw with commands that draw into graphics, then use SetImage to put it on a GUI?
Or are there other ways to attach a graphics object to a regular Gui with a titlebar, X, - and max buttons and a menu bar?
I'm not sure if I am being clear as to what I am trying to do, so feel free to ask for more explanation.

An example of this would be filling some shapes (lets say an eclipse and a rounded rectangle) and placing that in a picture control of an AHK Gui.

Thanks in advance
-Frankie

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2010, 1:52 am 
Offline

Joined: September 17th, 2010, 5:13 pm
Posts: 19
Hi there, I need a little help.
For example, in the Example 1: Gdip.Tutorial.1-Draw.Shapes.ahk, I would like to know how can I set an action when I press the elliptical shape and set another action when I press the rectangle.

Thanks in advance


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 12th, 2010, 5:03 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Hi Frankie. I think tutorial 9 should show you completely how to do this. You just create the bitmap, get the graphics for it, and do your drawing with it, then convert the bitmap into a gdi bitmap to setimage with. if you need to do many updates quickly, then BitBlt is the best way

em02044 the easiest way to achieve this is to make each shape a new hwnd with +Owner set so that it has no taskbar entry, and then you can use the OnClick event


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 16th, 2010, 3:46 am 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
I've got a slight problem.

I have your gdi+ code running saving images as my gui progress bar updates twice a second.

If it runs just like that it's all good - but if I click and drag the gui the save image function fails with the error code 10 in the dll call part.

Do you know what might be causing that?

According to the MSDN 10 is "FileNotfound" - I checked the output filename/extension and it's correct. The filename changes each time it's saved to incriment the filename - but it's perfectly find if you don't move the gui.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2010, 6:17 am 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
Nevermind the above post. It turns out the error was caused by some modifications I made - I reversed them and it seems to work fine now :P

Now i've just gota look into why it messed up..


Report this post
Top
 Profile  
Reply with quote  
PostPosted: November 21st, 2010, 8:03 am 
Offline

Joined: November 14th, 2008, 1:45 am
Posts: 80
Location: USA
Hello,

Thanks for these awesome functions! I am using "Example 3: Gdip.Tutorial.3-Create.Gui.From.Image.ahk" and my image is a local .bmp file. My question is how do I make the transparent color of the window white (FFFFFF)? Usually I would use Winset, Transcolor after creating the GUI by showing it and before removing the caption and making it always on top, but I can't seem to get it to work in the example script. How should I do it?

Thanks In Advance,
Sam.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 21st, 2010, 2:04 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
try Gdip_BitmapReplaceColour:

tic wrote:
I think this is what youre trying to do Frankie

Code:
#SingleInstance, Force
#NoEnv
SetBatchLines, -1

If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}
OnExit, Exit

Variation := 20

Gui, 1: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 1: Show, NA
hwnd1 := WinExist()

if !pBitmap := Gdip_CreateBitmapFromFile("Sample.jpg")
{
   MsgBox, 48, File loading error!, Could not load the image specified
   ExitApp
}

Gdip_GetDimensions(pBitmap, Width, Height)
pBitmapOut := Gdip_CreateBitmap(Width, Height)

hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_DrawImage(G, pBitmap, 0, 0, Width, Height, 0, 0, Width, Height)

UpdateLayeredWindow(hwnd1, hdc, (A_ScreenWidth-Width)//2, (A_ScreenHeight-Height)//2, Width, Height)
OnMessage(0x201, "WM_LBUTTONDOWN")
return

;#######################################################################

WM_LBUTTONDOWN(wparam, lparam)
{
   global G, pBitmap, pBitmapOut, Width, Height, Variation, hwnd1, hdc
   x := lparam & 0xffff, y := lParam >> 16
   E := Gdip_BitmapReplaceColour(pBitmap, pBitmapOut, Gdip_GetPixel(pBitmap, x, y), 0x00000000, Variation)
   Gdip_GraphicsClear(G)
   Gdip_DrawImage(G, pBitmapOut)
    UpdateLayeredWindow(hwnd1, hdc)
   SetTimer, Revert, -2000
}

;#######################################################################

Revert:
Gdip_GraphicsClear(G)
Gdip_DrawImage(G, pBitmap)
UpdateLayeredWindow(hwnd1, hdc)
return

;#######################################################################

Gdip_BitmapReplaceColour(pBitmap, ByRef pBitmapOut, Colour, ReplaceColour, Variation)
{
   static BitmapReplaceColour
   if !BitmapReplaceColour
   {
      MCode_BitmapReplaceColour := "83EC248B4424388B4C243C995683E2038BF103C28B542438C1FE10C1F90881E6FF00000081E1FF000000C1F8028974"
      . "2408894C244085D20F8E0A010000538B5C2430558B6C245033C903C0578B7C243C03C0894C241C89442430897C241889542420837C2440000F8EB9000"
      . "0008D43018BD32BD083C202895424282BF5894C244403C88BD32BD08B442440897424248954242C89442410EB0B8DA424000000008B7424248B542428"
      . "0FB6140A0FB6013BD67E0A8B74241403F53BD67C268B74244C2BF53BC67E248B5C244C03DD3BC38B5C24387C0E3BC67E128B74244C03F53BC67D088B4"
      . "424508907EB228B7424440FB6741E03C1E6080BF28B54242CC1E6080BF00FB6040AC1E6080BF08937834424440483C10483C704FF4C241075828B4C24"
      . "1C8B7424148B7C2418037C2430034C2448FF4C2420897C2418894C241C0F851EFFFFFF5F5D5BB8010000005E83C424C3"

      VarSetCapacity(BitmapReplaceColour, StrLen(MCode_BitmapReplaceColour)//2)
      Loop % StrLen(MCode_BitmapReplaceColour)//2      ;%
         NumPut("0x" SubStr(MCode_BitmapReplaceColour, (2*A_Index)-1, 2), BitmapReplaceColour, A_Index-1, "char")
   }

   Width := Gdip_GetImageWidth(pBitmap), Height := Gdip_GetImageHeight(pBitmap)
   if (Width != Gdip_GetImageWidth(pBitmapOut) || Height != Gdip_GetImageHeight(pBitmapOut))
      return -1

   if (Variation > 255 || Variation < 0)
      return -2

   E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1)
   E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2)
   if (E1 || E2)
      return -3

   E := DllCall(&BitmapReplaceColour, "uint", Scan01, "uint", Scan02, "int", Width, "int", Height, "int", Stride1, "int", Colour, "int", ReplaceColour, "int", Variation)
   Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapOut, BitmapData2)
   return 0
}


;#######################################################################

Esc::
Exit:
Gdip_DisposeImage(pBitmapOut), Gdip_DisposeImage(pBitmap)
SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
ExitApp
return


c++

Code:
int RemoveColour(unsigned char * sBitmap, unsigned int * dBitmap, int w, int h, int Stride, int Colour, int ReplaceColour, int v)
{
   int o, offset = Stride/4, R, G, B;
   int R1 = (Colour & 0x00ff0000) >> 16;
   int G1 = (Colour & 0x0000ff00) >> 8;
   int B1 = Colour & 0x000000ff;
   for (int y = 0; y < h; ++y)
   {
      for (int x = 0; x < w; ++x)
      {
         o = (4*x)+(y*Stride);
         R = sBitmap[2+o];
         G = sBitmap[1+o];
         B = sBitmap[o];
         if ((R > R1-v && R < R1+v) || (G > G1-v && G < G1+v) || (G > G1-v && G < G1+v))
            dBitmap[x+(y*offset)] =  ReplaceColour;
         else
            dBitmap[x+(y*offset)] = (sBitmap[3+o] << 24) | (R << 16) | (G << 8) | B;
      }
   }
   return 1;
}


it would be nice if the code tag on the forum didnt replace all tabs with spaces :? very frustrating!

only had a glance at your code, but I guess you arent clearing the graphics each time.

I would stick with the dll for a large project rather than using machine code


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2010, 5:46 am 
Offline

Joined: November 14th, 2008, 1:45 am
Posts: 80
Location: USA
tic wrote:
try Gdip_BitmapReplaceColour:
Thanks! That works great. Now what I would like to do is make the white pixels transparent on a rotated bitmap. I have started merging the two scripts, and so far this is what I have:
Code:
SetBatchLines, -1
#Include, Gdip.ahk

If !pToken := Gdip_Startup()
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}
OnExit, Exit

Gui, 1: +ToolWindow +AlwaysOnTop
Gui, 1: Add, Edit, x10 y10 w300 vFile,
Gui, 1: Add, Button, x+10 yp+0 w75 gFileSelect Default, &File...
Gui, 1: Add, Button, x+10 yp+0 w75 gGo, &Go
Gui, 1: Add, Slider, x10 y+10 w300 Tooltip vAngle Range0-360, 0
Gui, 1: Add, CheckBox, x+10 yp+0 vHorizontal, Flip horizontally
Gui, 1: Add, CheckBox, x+10 yp+0 vVertical, Flip vertically
Gui, 1: Show, x0 y0 AutoSize
Gui, 2: -Caption +E0x80000 +LastFound +OwnDialogs +Owner +AlwaysOnTop
Gui, 2: Show, NA

hwnd2 := WinExist()

OnMessage(0x201, "WM_LBUTTONDOWN")
Return

;#####################################################################

Go:

Gui, 1: +OwnDialogs
Gui, 1: Submit, NoHide

If !pBitmap := Gdip_CreateBitmapFromFile(File)
Return

OriginalWidth := Gdip_GetImageWidth(pBitmap), OriginalHeight := Gdip_GetImageHeight(pBitmap)
Ratio := OriginalWidth/OriginalHeight

If (OriginalWidth >= A_ScreenWidth//1.312) || (OriginalHeight >= A_ScreenHeight//1.312)
{
   If (OriginalWidth >= OriginalHeight)
   Width := A_ScreenWidth//1.312, Height := Width*(1/Ratio)
   Else
   Height := A_ScreenHeight//1.312, Width := Height*Ratio
}
Else
Width := OriginalWidth, Height := OriginalHeight


Gdip_GetRotatedDimensions(Width, Height, Angle, RWidth, RHeight)
Gdip_GetRotatedTranslation(Width, Height, Angle, xTranslation, yTranslation)
hbm := CreateDIBSection(RWidth, RHeight)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc), Gdip_SetInterpolationMode(G, 7)
Gdip_TranslateWorldTransform(G, xTranslation, yTranslation)
Gdip_RotateWorldTransform(G, Angle)
If Horizontal
Gdip_ScaleWorldTransform(G, -1, 1), Gdip_TranslateWorldTransform(G, -Width, 0)
If Vertical
Gdip_ScaleWorldTransform(G, 1, -1), Gdip_TranslateWorldTransform(G, 0, -Height)
Gdip_DrawImage(G, pBitmap, 0, 0, Width, Height, 0, 0, OriginalWidth, OriginalHeight)
Gdip_ResetWorldTransform(G)
UpdateLayeredWindow(hwnd2, hdc, (A_ScreenWidth-RWidth)//1.312, (A_ScreenHeight-RHeight)//1.312, RWidth, RHeight)
SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap)
Return



;#####################################################################

; This is a simple subroutine to select images and change the editbox with the image teh user selects
FileSelect:
Gui, 1: +OwnDialogs
Gui, 1: Submit, NoHide

FileSelectFile, File,,, Select image
If Errorlevel
Return
GuiControl,, File, %File%
Return

;#####################################################################

WM_LBUTTONDOWN(wparam, lparam)
{
   If (A_Gui = 2)
   {
   PostMessage, 0xA1, 2
   global G, pBitmap, pBitmapOut, Width, Height, Variation, hwnd2, hdc
   x := lparam & 0xffff, y := lParam >> 16
   E := Gdip_BitmapReplaceColour(pBitmap, pBitmapOut, Gdip_GetPixel(pBitmap, x, y), 0x00000000, Variation)
   Gdip_GraphicsClear(G)
   Gdip_DrawImage(G, pBitmapOut)
    UpdateLayeredWindow(hwnd2, hdc)
   }
}

;#######################################################################

Gdip_BitmapReplaceColour(pBitmap, ByRef pBitmapOut, Colour, ReplaceColour, Variation)
{
   static BitmapReplaceColour
   if !BitmapReplaceColour
   {
      MCode_BitmapReplaceColour := "83EC248B4424388B4C243C995683E2038BF103C28B542438C1FE10C1F90881E6FF00000081E1FF000000C1F8028974"
      . "2408894C244085D20F8E0A010000538B5C2430558B6C245033C903C0578B7C243C03C0894C241C89442430897C241889542420837C2440000F8EB9000"
      . "0008D43018BD32BD083C202895424282BF5894C244403C88BD32BD08B442440897424248954242C89442410EB0B8DA424000000008B7424248B542428"
      . "0FB6140A0FB6013BD67E0A8B74241403F53BD67C268B74244C2BF53BC67E248B5C244C03DD3BC38B5C24387C0E3BC67E128B74244C03F53BC67D088B4"
      . "424508907EB228B7424440FB6741E03C1E6080BF28B54242CC1E6080BF00FB6040AC1E6080BF08937834424440483C10483C704FF4C241075828B4C24"
      . "1C8B7424148B7C2418037C2430034C2448FF4C2420897C2418894C241C0F851EFFFFFF5F5D5BB8010000005E83C424C3"

      VarSetCapacity(BitmapReplaceColour, StrLen(MCode_BitmapReplaceColour)//2)
      Loop % StrLen(MCode_BitmapReplaceColour)//2      ;%
         NumPut("0x" SubStr(MCode_BitmapReplaceColour, (2*A_Index)-1, 2), BitmapReplaceColour, A_Index-1, "char")
   }

   Width := Gdip_GetImageWidth(pBitmap), Height := Gdip_GetImageHeight(pBitmap)
   if (Width != Gdip_GetImageWidth(pBitmapOut) || Height != Gdip_GetImageHeight(pBitmapOut))
      return -1

   if (Variation > 255 || Variation < 0)
      return -2

   E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1)
   E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2)
   if (E1 || E2)
      return -3

   E := DllCall(&BitmapReplaceColour, "uint", Scan01, "uint", Scan02, "int", Width, "int", Height, "int", Stride1, "int", Colour, "int", ReplaceColour, "int", Variation)
   Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapOut, BitmapData2)
   return 0
}


;#######################################################################

; If the user closes the gui or closes the program then we want to shut down gdi+ and exit the application
Esc::
GuiClose:
Exit:
Gdip_DisposeImage(pBitmapOut), Gdip_DisposeImage(pBitmap)
SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
ExitApp
Return

Eventually I'll have time to figure out what every line actually does, but sadly that won't be until I start on my next project sometime in 2011. Until then, I could use some more help. How else do I need to change WM_LBUTTONDOWN(wparam, lparam) so that it works properly in the new script? Is there anywhere else so far that I have goofed? I'm pretty sure there is... :( .

I really appreciate the help,
Sam.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2010, 1:35 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Hi Sam

I dont mean to be unhelpful, but looking at your code I can see that the problems you are having are with the actual language itself and not the gdi+ library

You can see that in your WM_LBUTTONDOWN event the variable names are not the same as in the rest of the script, and also you have declared your variables global inside an if statement (not sure if that even works??). Also you may notice that you have already disposed of all of those objects youre using, and pBitmapOut has never been created


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 22nd, 2010, 10:48 pm 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
Tic:

I've been messing around with GDI+ and trying to use your locked pixel functions.

I was wondering, is there a way to make it so if you pass a invalid x/y to the Gdip_SetLockBitPixel() function it doesn't crash that thread?

I can always do If X < 0 or X > Max_X and so on but that's not efficient as I would have to do the check every time I call the function even if the location is valid it will still slow it down.


Thanks,
Robert


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2010, 1:31 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
rseding91 wrote:
Tic:

I've been messing around with GDI+ and trying to use your locked pixel functions.

I was wondering, is there a way to make it so if you pass a invalid x/y to the Gdip_SetLockBitPixel() function it doesn't crash that thread?

I can always do If X < 0 or X > Max_X and so on but that's not efficient as I would have to do the check every time I call the function even if the location is valid it will still slow it down.


Thanks,
Robert


No way I can think of off the top of my head. it crashes as the script is trying to access another location in memory and change its values, which it does not have access to do. there is no equivalent to c#'s try+catch

however....it shouldnt be necessary to have an if statement for this....why not just loop the correct number of times?


Code:
y := 0
Loop, %Height%
{
   Loop, %Width%
      ARGB := Gdip_GetLockBitPixel(Scan0, A_Index-1, y, Stride)
   y++
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 23rd, 2010, 3:50 am 
Offline

Joined: June 7th, 2010, 3:40 pm
Posts: 553
I did end up doing that. But I wanted to see if I could find a easy way to make all the old locations i've got work.

I found a work around so that's done.

I have another question: in the "FastPixelGetColor" post you said you could do the pixel lookups even faster with machine code?

I was wondering, could that be done the other way around? setting pixel colors with machine code instead of looking them up?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1000 posts ]  Go to page Previous  1 ... 34, 35, 36, 37, 38, 39, 40 ... 67  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Google Feedfetcher, JamixZol, rbrtryn, Stigg, Yahoo [Bot] and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group