Author Topic: GDIplus - brightness  (Read 13049 times)

0 Members and 1 Guest are viewing this topic.

Offline Edwin Knoppert

  • Sr. Member
  • ****
  • Posts: 254
  • User-Rate: +11/-4
    • Hellobasic.com
GDIplus - brightness
« on: October 17, 2011, 12:19:27 PM »
Can't find the way to do this with PB:

http://msdn.microsoft.com/en-us/library/ms536278(v=vs.85).aspx

Just need to brighten an image via a slider.
Got so far  ;D

Type BrightnessContrastParams
  brightnessLevel As Long
  contrastLevel As Long
End Type

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2512
  • User-Rate: +209/-0
Re: GDIplus - brightness
« Reply #1 on: October 17, 2011, 04:02:22 PM »
Looks like a good start...

Now create an Effects object with GdipCreateEffect, fill the brightnessLevel member of the structure with the wanted value, set the parameters with GdipSetEffectParameters, draw the image using GdipDrawImageFX and delete the effects object with GdipDeleteEffect.

Offline Edwin Knoppert

  • Sr. Member
  • ****
  • Posts: 254
  • User-Rate: +11/-4
    • Hellobasic.com
Re: GDIplus - brightness
« Reply #2 on: October 18, 2011, 10:10:03 AM »
Thanks!

First issue i found:
Byref Guid doesn't do it:

Declare Function GdipCreateEffect Lib "GDIPLUS.DLL" Alias "GdipCreateEffect" ( _
   ByRef Guid As Guid _                                 ' __in  const GUID guid
 , ByRef effect As Dword _                              ' __out CGpEffect **effect
 ) As Long                                              ' GpStatus

I changed it to ByVal and i get 0 for result and pointer to effects.

Note: did not use your declare but a call dword as:

    g = Guid$("{D3A1DBE1-8EC4-4C17-9F4C-EA97AD1C343D}")
    Call Dword CDW Using VD_GdipCreateEffect( g, effect ) To hr

Declare Function VD_GdipCreateEffect( _
   ByVal Guid As Guid _                                 ' __in  const GUID guid
 , ByRef effect As Dword _                              ' __out CGpEffect **effect
 ) As Long                                              ' GpStatus
)

Later..

Offline Edwin Knoppert

  • Sr. Member
  • ****
  • Posts: 254
  • User-Rate: +11/-4
    • Hellobasic.com
Re: GDIplus - brightness
« Reply #3 on: October 18, 2011, 10:41:35 AM »
It works :)

Offline Edwin Knoppert

  • Sr. Member
  • ****
  • Posts: 254
  • User-Rate: +11/-4
    • Hellobasic.com
Re: GDIplus - brightness
« Reply #4 on: October 18, 2011, 11:32:33 AM »
Any idea how to strecth during draw?
The matrix param seems to be the part i need(?)
Don't know how that works.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2512
  • User-Rate: +209/-0
Re: GDIplus - brightness
« Reply #5 on: October 18, 2011, 01:27:37 PM »
Create a Matrix object with GdipCreateMatrix, call one of  the GdipCreateMatrixXXX, e.g. GdipCreateMatrix2 functions, and later delete it with GdipDeleteMatrix.

Offline Edwin Knoppert

  • Sr. Member
  • ****
  • Posts: 254
  • User-Rate: +11/-4
    • Hellobasic.com
Re: GDIplus - brightness
« Reply #6 on: October 18, 2011, 01:56:19 PM »
Thanks, works, FAI:

GdipCreateMatrix2(...)

xscale, 0, 0, yscale, offsetx, offsety like: 1, 0, 0, 1, 400, 40

Offline Patrice Terrier

  • Hero Member
  • *****
  • Posts: 934
  • User-Rate: +62/-1
    • www.zapsolution.com
Re: GDIplus - brightness
« Reply #7 on: October 18, 2011, 03:49:33 PM »
Quote
FUNCTION UseBrightnessMatrix(BYVAL imgAttr AS LONG, BYVAL Value AS LONG) AS LONG
  ' Range value 0 to 255 (-1 to 1, with 0 = neutral)
    LOCAL c AS ColorMatrix, V AS SINGLE
    Value = MAX&(MIN&(Value + 1, 256), 0)
    V = -1 + (Value / 128)
  ' Create the ImageAttributes object
    IF imgAttr = 0 THEN CALL GdipCreateImageAttributes(imgAttr)
  ' Fill the color matrix
  ' Red            Green          Blue           Alpha          W
    c.m(0, 0) = 1: c.m(1, 0) = 0: c.m(2, 0) = 0: c.m(3, 0) = 0: c.m(4, 0) = 0
    c.m(0, 1) = 0: c.m(1, 1) = 1: c.m(2, 1) = 0: c.m(3, 1) = 0: c.m(4, 1) = 0
    c.m(0, 2) = 0: c.m(1, 2) = 0: c.m(2, 2) = 1: c.m(3, 2) = 0: c.m(4, 2) = 0
    c.m(0, 3) = 0: c.m(1, 3) = 0: c.m(2, 3) = 0: c.m(3, 3) = 1: c.m(4, 3) = 0
    c.m(0, 4) = V: c.m(1, 4) = V: c.m(2, 4) = V: c.m(3, 4) = 0: c.m(4, 4) = 1
  ' And set its color matrix
    CALL GdipSetImageAttributesColorMatrix(imgAttr&, %ColorAdjustTypeDefault, %TRUE, c, BYVAL 0, %ColorMatrixFlagsDefault)
    FUNCTION = imgAttr
END FUNCTION
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Edwin Knoppert

  • Sr. Member
  • ****
  • Posts: 254
  • User-Rate: +11/-4
    • Hellobasic.com
Re: GDIplus - brightness
« Reply #8 on: October 27, 2011, 04:45:45 AM »
I have not investigated which call fails yet but on a different Windows 7 computer on of the calls does not seem to be supported.
If i read your declare it's embedded with a
#If (%GDIPVER >= &H0110)
#endif
If i read MSDN it says it's available from Windows XP and up
http://msdn.microsoft.com/en-us/library/ms536058(v=vs.85).aspx

Like i said i have to check the actual call but i asume the GdipDrawImageFX() is the critter here?

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2512
  • User-Rate: +209/-0
Re: GDIplus - brightness
« Reply #9 on: October 27, 2011, 05:43:36 AM »
It requires GDI+ 1.1.

Offline Patrice Terrier

  • Hero Member
  • *****
  • Posts: 934
  • User-Rate: +62/-1
    • www.zapsolution.com
Re: GDIplus - brightness
« Reply #10 on: October 27, 2011, 09:27:09 AM »
I avoid to use GDI+ 1.1, because there is no standard distribution for it.

So far i didn't found anything in version 1.1, that couldn't be done with the standard version, but of course that come at a price:
more personnal work, and a good understanding of the fundamentals of GDI+ matrix.

...

Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Edwin Knoppert

  • Sr. Member
  • ****
  • Posts: 254
  • User-Rate: +11/-4
    • Hellobasic.com
Re: GDIplus - brightness
« Reply #11 on: October 27, 2011, 05:49:30 PM »
Terribly irritating, especially the number of issues i already had last week using gdiplus while i thought it would be a breeze to implement.
Does your code handle brightness + contrast?
Is that matrix working identical to my code (output)?

I thought this would help for v1.1 but i don't had the time yet, found out that it's about a Vista computer:
http://support.microsoft.com/KB/958911

Added:
Can't i use my original code and manipulate the image and draw it using an older call instead of drawing the image and effects with the new call directly?
I can hold a copy of the image before modifying it.
« Last Edit: October 27, 2011, 05:52:17 PM by Edwin Knoppert »

Offline Patrice Terrier

  • Hero Member
  • *****
  • Posts: 934
  • User-Rate: +62/-1
    • www.zapsolution.com
Re: GDIplus - brightness
« Reply #12 on: October 27, 2011, 07:40:14 PM »
Quote
Does your code handle brightness + contrast?

Yes, see PhotoSetup

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Edwin Knoppert

  • Sr. Member
  • ****
  • Posts: 254
  • User-Rate: +11/-4
    • Hellobasic.com
Re: GDIplus - brightness
« Reply #13 on: October 29, 2011, 03:06:36 PM »
FYI:
Will try your code and the code being posted on the PB forum.
I need brightness + contrast though
(Complex matrix stuff :) )

Offline Larry Charlton

  • Newbie
  • *
  • Posts: 14
  • User-Rate: +5/-3
Re: GDIplus - brightness
« Reply #14 on: October 30, 2011, 01:05:17 AM »
If you grab the GDIPlus testing code I've been writing it has a contrast matrix.  Just multiply the two together to get both.