Consulting

Results 1 to 6 of 6

Thread: set color saturation of image with vba

  1. #1
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location

    set color saturation of image with vba

    Hi,

    I am trying to set the color saturation of a jpg image with VBA (excel 2010).
    I have found an msoeffectsaturation property, but cant find how to use it.

    I wish to toggle the saturation of the image from greyscale to full color as part of a click-on, click-off procedure.

    has anyone done this?
    Clueless
    Last edited by werafa; 03-12-2013 at 05:35 PM.
    Remember: it is the second mouse that gets the cheese.....

  2. #2
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location
    I found this on a french language blog. it seems to call the right things...

    [vba]Sub Effets()
    Dim s As Shape
    Set myDocument = Worksheets(1)
    Set s = ActiveWorkbook.Worksheets(1).Shapes(1)
    With s.Fill.PictureEffects
    .Insert(msoEffectSaturation).EffectParameters(1).Value = 0.5
    Dim brightnessContrast As PictureEffect
    Set brightnessContrast = .Insert(msoEffectBrightnessContrast)
    brightnessContrast.EffectParameters(1).Value = 0.1 ' Luminosité
    brightnessContrast.EffectParameters(2).Value = -0.3 ' Contraste
    ' Remove all Picture effects.
    While .Count > 0
    .Delete (1)
    Wend
    End With
    End Sub[/vba]
    my implementation of a single line of code
    [vba]myPicture.Fill.PictureEffects.Insert(msoEffectSaturation).EffectParameters( 1).Value = 0[/vba] doesn't work though
    Remember: it is the second mouse that gets the cheese.....

  3. #3
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    That line works for me. Does it not do anything at all when you try it or does it error? If it does nothing, are you sure you are referring to the correct shape?
    Be as you wish to seem

  4. #4
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location
    I am fairly sure I have the right shape - other code did work. I was trying to use this on a picture I was turning into a button. the code ran - but did nothing. Alternative explanation is that I was also playing with 3d formats and perspective - and the effects might be mutually exclusive in some way.

    anyway the code is not at fault, so anyone who wants to have a play, go your hardest...

    There is little documentation on this so, it is either a new/obscure function or not the best way to do this. Thanks for your comment
    Remember: it is the second mouse that gets the cheese.....

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Couldn't you toggle with

    [vba]Sub toggle()
    Dim oshp As Shape
    Set oshp = ActiveWorkbook.Worksheets(1).Shapes(1)
    With oshp.PictureFormat
    Select Case .ColorType
    Case Is = msoPictureGrayscale
    .ColorType = msoPictureAutomatic
    Case Is = msoPictureAutomatic
    .ColorType = msoPictureGrayscale
    End Select
    End With
    End Sub[/vba]

    OR to use saturation

    [VBA]With s.Fill.PictureEffects
    .Delete (1)
    .Insert(msoEffectSaturation).EffectParameters(1).Value = 0.5 'whatever
    End With[/VBA]
    Last edited by John Wilson; 05-22-2013 at 03:41 AM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    VBAX Mentor
    Joined
    Aug 2012
    Posts
    367
    Location
    It may be that the saturation setting needs to be deleted, then reset - and that inserting the saturation value as I have attempted is not the same as editing the value.

    I do like the 'understandablenes by ignoramuses' atribute of the greyscale toggle code however, and shall give this option a shot when I play next.

    Thanks
    Tim
    Remember: it is the second mouse that gets the cheese.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •