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
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.
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..
It works :)
Any idea how to strecth during draw?
The matrix param seems to be the part i need(?)
Don't know how that works.
Create a Matrix object with GdipCreateMatrix, call one of the GdipCreateMatrixXXX, e.g. GdipCreateMatrix2 functions, and later delete it with GdipDeleteMatrix.
Thanks, works, FAI:
GdipCreateMatrix2(...)
xscale, 0, 0, yscale, offsetx, offsety like: 1, 0, 0, 1, 400, 40
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
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?
It requires GDI+ 1.1.
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.
...
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.
QuoteDoes your code handle brightness + contrast?
Yes, see
PhotoSetup (http://www.jose.it-berater.org/smfforum/index.php?topic=2341.msg7290#msg7290)
...
FYI:
Will try your code and the code being posted on the PB forum.
I need brightness + contrast though
(Complex matrix stuff :) )
If you grab the GDIPlus testing code I've been writing it has a contrast matrix. Just multiply the two together to get both.
Yes i seen it, only thing is that the scale/scope differs from the gdiplus effects -1/1 vs -255/255
I have the feeling that a float can not reach the same potential this way (?)
Contrast
// factor > 1.0f increases the contrast
// 0.0f < factor < 1,0f decreases the contrast
REAL factorT = 0.5f * (1.0f - factor);
ColorMatrix colorMatrix =
{
factor, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, factor, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, factor, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
factorT, factorT, factorT, 0.0f, 1.0f
};
Somewhere this week i'll continue on this.
I have some other projects interfering :)
Thanks,
Btw, i was using a trackbar but does not seem to accept negative ranges (-1 <> 1)
I shifted it to positive values but the tracking tooltip shows those values as well.
I wonder if i can use negative values or customly set the value in the tooltip.
Last resort would be to prepare a tracking tooltip from scratch.