Home All Groups Group Topic Archive Search About

Adjusting Contrast or Brightness in VB6

Author
4 Jun 2005 3:26 AM
jm7
In VB6:  Does anyone know of a very efficient and fast way of altering the
Contrast or brightness of an image (in a picturebox) on the screen.  The
image does not have to be saved.

Thanks.

Author
4 Jun 2005 12:29 PM
Mike D Sutton
> In VB6:  Does anyone know of a very efficient and fast way of altering the
> Contrast or brightness of an image (in a picturebox) on the screen.  The
> image does not have to be saved.

Have a look at the "Colour adjustment demo" or "Edge detection / Edge snap / Filter kernel" demos on my site, both of which
demonstrate how to perform brightness/contrast adjustments; the former using the Wni32 API (WinNT based OS' only) and the latter
through code alone (OS unspecific.)
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
5 Jun 2005 6:44 AM
jm7
Hi Mike,

Thanks for the sample code - it works brilliantly - I am just amazed at how
powerful and fast VB6 can be now.

In the redraw procedure - I can't seem to work why you call

   Call SetColorAdjustment(picPreview.hDC, NewAdjust)
..
..
..
..
  followed by :
    Call SetColorAdjustment(picPreview.hDC, OrigAdjust)
in the same procedure.

I am also looking forward to spending some tim egoing through your
tutorials.

John




"Mike D Sutton" <ED***@mvps.org> wrote in message
news:Oer7SFQaFHA.3528@TK2MSFTNGP09.phx.gbl...
> > In VB6:  Does anyone know of a very efficient and fast way of altering
the
> > Contrast or brightness of an image (in a picturebox) on the screen.  The
> > image does not have to be saved.
>
> Have a look at the "Colour adjustment demo" or "Edge detection / Edge snap
/ Filter kernel" demos on my site, both of which
> demonstrate how to perform brightness/contrast adjustments; the former
using the Wni32 API (WinNT based OS' only) and the latter
Show quoteHide quote
> through code alone (OS unspecific.)
> Hope this helps,
>
>     Mike
>
>
>  - Microsoft Visual Basic MVP -
> E-Mail: ED***@mvps.org
> WWW: Http://EDais.mvps.org/
>
>
Author
5 Jun 2005 9:18 AM
Mike D Sutton
> Thanks for the sample code - it works brilliantly - I am just amazed at how
> powerful and fast VB6 can be now.
>
> In the redraw procedure - I can't seem to work why you call
>
>    Call SetColorAdjustment(picPreview.hDC, NewAdjust)
> .
> .
> .
> .
>   followed by :
>     Call SetColorAdjustment(picPreview.hDC, OrigAdjust)
>  in the same procedure.

The colour adjustment is applied to the entire DC, and any drawing commands (that honour the colour adjustment properties) will
adjust their output to the currently applied mode.  Since we don't want any other drawing on the DC to be colour adjusted (just the
image we're drawing ourselves) I back the initial default colour adjustment properties up at the start of the procedure and re-apply
those at the end to restore the DC back to normal.  This way any drawing done to the window by VB or any other API's will not be
affected.
In this case since there's very little drawing going on it's probably safe to apply the adjustment once, but IMO it's cleaner to
leave the DC the way you found it and good practice to get into if you're doing lots of GDI work.

> I am also looking forward to spending some time going through your
> tutorials.

Good luck, let me know if you have any problems with them.
Cheers,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/