• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

GDIplus - brightness

Started by Edwin Knoppert, October 17, 2011, 12:19:27 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Edwin Knoppert

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

José Roca

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.

Edwin Knoppert

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..

Edwin Knoppert


Edwin Knoppert

Any idea how to strecth during draw?
The matrix param seems to be the part i need(?)
Don't know how that works.

José Roca

Create a Matrix object with GdipCreateMatrix, call one of  the GdipCreateMatrixXXX, e.g. GdipCreateMatrix2 functions, and later delete it with GdipDeleteMatrix.

Edwin Knoppert

Thanks, works, FAI:

GdipCreateMatrix2(...)

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

Patrice Terrier

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

Edwin Knoppert

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?

José Roca


Patrice Terrier

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

Edwin Knoppert

#11
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.

Patrice Terrier

QuoteDoes your code handle brightness + contrast?

Yes, see PhotoSetup

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

Edwin Knoppert

FYI:
Will try your code and the code being posted on the PB forum.
I need brightness + contrast though
(Complex matrix stuff :) )

Larry Charlton

If you grab the GDIPlus testing code I've been writing it has a contrast matrix.  Just multiply the two together to get both.