Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#21 Color Dropper for ColorDialog

closed-accepted
Robin Krom
None
5
2012-03-31
2012-02-13
Hicoder
No

allows greenshot to pick a color from any location on the screen from the colordialog. still working on how to get this feature on the toolstrip. built on svn1652

i heavily modfied the the project file so i could navigate easier, did not want to include it with the patch. So Dropper.cs and Zoomer.cs need to be added to the Greenshot.Controls and Greenshot.Forms folders respectively.

Discussion

  • Hicoder
    Hicoder
    2012-02-13

    Adds Color Dropper to ColorDialog.cs

     
    Attachments
  • Robin Krom
    Robin Krom
    2012-02-13

    • assigned_to: nobody --> apex75
     
  • Robin Krom
    Robin Krom
    2012-02-13

    Hi,

    thanks a lot for the patch! I still wanted to make this, now at least I don't have to look at how to implement the SetCapture/ReleaseCapture...

    If I would just take your patch we would get a lot of bug reports due to undisposed resources! Maybe these don't show up right away... but you are creating a GDI resources without ever disposing/releasing them: bitmaps, graphics, icons and also using "copyfromscreen" (which has a "DC" leak). But I will free the resources, see if I can use something else as copyfromscreen and report back.

    Best wishes,
    Robin

     
  • Hicoder
    Hicoder
    2012-02-13

    I realized that when i opened the project again this morning. The zoomer window seems to lag a little and I am uncertain why. i thought creating the bitmap and graphics object might have been extremely costly, which is why i made them members. i have written something similar in C and have had no issues. I'm not sure if its a framework problem, or a problem with my code.

     
  • Robin Krom
    Robin Krom
    2012-02-14

    At least you should implement a Dispose method where you dispose the bitmap, cursor and graphics objects. There will be no problems when the code is used once or twice but every call creates GDI resources which aren't freed. This is needed for all objects you create e.g Bitmap, Region, Brush, Icon, Cursor, Pen and Graphics objects. Also when using P/Invokes you need to read the documentations if something needs to be freed.

    Greenshot <0.8.1 has this GDI leak problem, after using it for a while you will get funny exceptions like Outofmemory or illegalarguments etc...

    I changed the copyfromscreen to use getpixel with a DC, which if implemented correctly doesn't leak like the copyfromscreen. (google copyfromscreen and leak)

    I also noticed the lag behind and the fact that somehow the Zoomer starts tranparent... Until movement briefly stops, will look at it. Maybe we din't need the getcapture and can use the build in capture of controls with less issues. I believe we could also lose the message filter, use the mousecapturefinished ( or something like that) as replacement.

    best wishey,
    Robin

     
  • In the original code i had using() statements around the Bitmap and Graphics objects in setHotSpot method(which is what i thought the patch had in it). I did not know about CopyFromScreen having a memory leak.

    Thanks for the info.

     
  • Hicoder
    Hicoder
    2012-02-14

    The message filter is for Canceling the Dropper with the esc key. Framework doesnt send key events when you have mouse capture.

     
  • Robin Krom
    Robin Krom
    2012-02-14

    I was wondering if the mousecapturechanged event is called if someone presses the esc..

    Anyway, I'll leave it as is, you can see how I killed some of your code... ;-)
    I solved the weird effect I had, dragging caused an initial transparent form, with using an call to update.
    Looks okay now...

    Thanks!

     
  • Robin Krom
    Robin Krom
    2012-03-31

    Will be in Greenshot 1.0, coming soon!!

     
  • Robin Krom
    Robin Krom
    2012-03-31

    • status: open --> closed-accepted