Prod.: Engine, ver.: 6022, ID: 60001635, Wish : Adjusting an image's contrast, gamma, brightness and color

Wish : Adjusting an image's contrast, gamma, brightness and color

Article60001635
TypeWish
ProductEngine
Version6022
Date Added3/1/2012
FixedYes [5/1/2012]
Submitted byBruce Jacobs
Keywords

Subject

Adjusting an image's contrast, gamma, brightness and color

Summary

Is there any way using the VectorDraw Framework that I could adjust the contrast, gamma or brightness of a displayed image? Also is it possible to make it more reddish, greenish or bluish ?

Solution

In version 6023 we did some changes in our Image Dialogs and also added some functionality which give to our clients the ability to edit an Image.
First of all in the main Image Dialog we added 2 functions.



When an Image is selected then these options are available.
  • The "Bind" CheckBox if checked indicates that the Image is Binded to the Document. This means that the Filename of the Image is not taken into consideration and the Bytes of the Image are inside the Document and will be saved.
        If you uncheck this checkbox then if the Filename of the Image exists then it will use this filename and load the Image , else a different Filename for the Image will be asked.
  • The other button "Edit Image" will open a nwely created dialog and will give the user the ability to manipulate the Image. Note that any change to the Image will make it Bind since the bytes of the Image are changed and the filename is no longer valid.     You can also choose to Edit an Image in this dialog by DoubleClicking to a selected Image.

    The new dialog that we created for Editing Images is the following.


    This dialog give the ability to change/edit the Image selected. You can apply a grayscale , sapia and invert colors effect. Also adjust the Brightness / Contrast of the Image and even Gamma of the Colors. The user can change also the colors of the Image by adding more blue or red to the Image , and of course rotating and flipping the Image.
    You can also export the current modified Image to a filename using the Export button.
    All these adjustments will make the Image Bind to the Document if the user presses the ok button and the changes then are applied.

    Programmatically you can call this extra dialog to edit a specific vdImageDef of the Document like below :

    c# code
    //Get the Image to Edit
    vdImageDef img = vdFramedControl.BaseControl.ActiveDocument.Images[0] as vdImageDef;
    DialogResult res = VectorDraw.Professional.Dialogs.FrmImageEdit.Show( vdFramedControl.BaseControl.ActiveDocument, img);

    and also for the ocx.
    Dim img As VectorDraw_Professional.vdImageDef
    Dim dialogs As New VectorDraw_Professional.VdrawDialogs
    Set img = VDraw1.ActiveDocument.images(0).WrapperObject
    dialogs.InitializeVdrawDialogs VDraw1.ActiveDocument.WrapperObject
    dialogs.GetEditImageDialog img

    To the vdImageDef object we added the following methods which could be usefull to Edit programmatically an ImageDef. Also if any of these methods are called the Image is Binded to the Document.
    summary>This static method will apply the passed effects controlled from the parameters to the passed b Bitmap.
    param name="b">The Bitmap object to apply the effects.
    param name="Grayscale">A boolean value representing if a gray effect will be applied. Pass true in order to apply the Grayscale effect.
    param name="Sepia">A boolean value representing if a sepia effect will be applied. Pass true in order to apply the sepia effect.A standard value of 20 is used for this effect.
    param name="Invert">A boolean value representing is the colors of the Bitmap will be inverted. Pass true in order to Invert the colors.
    param name="brightness">An Integer value representing the Brightness to be applied to the Bitmap. Values should be from -255 to 255. Pass 0 to not apply any Brightness to the Bitmap.
    param name="contrast">An Integer value representing the Contrast to be applied to the Bitmap.Values should be from -100 to 100. Pass 0 to not apply any Contrast to the Bitmap.
    param name="ColorsRed">An Integer value representing the Red alteration of the Bitmap. Values should be from -255 to 255. Pass 0 to not apply any red effect to the Bitmap.
    param name="ColorsGreen">An Integer value representing the Green alteration of the Bitmap. Values should be from -255 to 255. Pass 0 to not apply any Green effect to the Bitmap.
    param name="ColorsBlue">An Integer value representing the Blue alteration of the Bitmap. Values should be from -255 to 255. Pass 0 to not apply any Blue effect to the Bitmap.
    param name="GammaRed">A double value that represents the Red Gamma effect to be applied. Valid values are from 0.2 to 5.0. Pass 1.0 to not apply any Red Gamma effect to the Bitmap.
    param name="GammaGreen">A double value that represents the Green Gamma effect to be applied. Valid values are from 0.2 to 5.0. Pass 1.0 to not apply any Green Gamma effect to the Bitmap.
    param name="GammaBlue">A double value that represents the Blue Gamma effect to be applied. Valid values are from 0.2 to 5.0. Pass 1.0 to not apply any Blue Gamma effect to the Bitmap.
    param name="retbytes">If the PixelFormat of the Bitmap is not 24bit then changes to 24bit and this array contains the changed 24bit bytes of the Image.This is used in palette images mostly.
    returns>True if the operation was succesfull.
    public static bool ApplyEffects(System.Drawing.Bitmap b, bool Grayscale, bool Sepia, bool Invert, int brightness, int contrast, int ColorsRed, int ColorsGreen, int ColorsBlue, double GammaRed, double GammaGreen, double GammaBlue, out byte[] retbytes)
    summary>This method changes this vdImageDef's Bitmap by applying the passed RotateFlipType Rotation and Flip.Note that after this call the Image will be Binded to the Document.
    param name="type">A VectorDraw.Render.vdRotateFlipTypeEnum type to apply to this vdImageDef's Bitmap.
    remarks>Note that after this call the Image will be Binded to the Document.
    public void ApplyRotationFlip(VectorDraw.Render.vdRotateFlipTypeEnum type)