0

I'm trying to write a macro in PowerPoint that, for each picture, iterates over each pixel so as to get the current color of each pixel and then be able to change the color. I have found some references about how to do this in VBA, but they refer to Excel, so many functions are not applicable in my case in PowerPoint.

I am not quite familiar with PowerPoint VBA, but my approach was:

Sub ChangeColor()
    Dim oshp As Shape
    Dim osld As Slide
    For Each osld In ActivePresentation.Slides
        For Each oshp In osld.Shapes
            If oshp.Name Like "Picture*" Then
                'FUNCTION TO ITERATE OVER PIXELS AND CHANGE COLOR OF EACH PIXEL
            End If
        Next oshp
    Next osld
End Sub

However, I don't know how to iterate over pixels. Can somebody help me to understand how can I do this?

Many thanks in advance!

JN_2605
  • 145
  • 6
  • Your question looks strange to me. Do you really want changing pixels color without having any idea regarding the existing pixel color? May we understand **why such a need**? – FaneDuru Nov 21 '22 at 12:22
  • For a given picture, my idea is to get the current color of each pixel and then change the color of that pixel. For example, imagine I want to change all blue pixels by red pixels, then I need to get the current color of each pixel and then change the RGB code decreasing the B and increasing the R – JN_2605 Nov 21 '22 at 12:26
  • Is this a **need** or you only try playing with pixels color? I aske above **why such a need**. I meant the global need, if any... – FaneDuru Nov 21 '22 at 12:29
  • PowerPoint shapes are vector graphics. They don't really have "pixels" unless you convert them to a bitmap. – braX Nov 21 '22 at 12:30
  • 1
    @braX He is talking about `pictures`... – FaneDuru Nov 21 '22 at 12:33
  • Not shapes with `Picture` in the name? One can rename any shape. – braX Nov 21 '22 at 12:34
  • Let me explain the need for this better. I have a PowerPoint presentation in which all colors are bluish, and I want to make a macro that will change all colors to reddish colors. For text and shapes I have achieved this by permuting the R and B colors of the RGB code of the corresponding text/shape. What I want to do now is the same but for images, and in this case the only solution I can think of is to permute the R and B colors of each pixel of the image, but for that I need to iterate over the pixels. – JN_2605 Nov 21 '22 at 13:05
  • This way of putting the problem looks simplistic for me, no offence. What RGB colors do you consider being Blue, for instance? It is a very large field of nuances able to be considered blue. Very rarely, or never a picture can contain only the base colors... For instance, to replace light red with light blue it is not so simple as it looks. – FaneDuru Nov 21 '22 at 13:13
  • 1
    I agree that it is not trivial which colors to consider blue. Just now I am considering a color is blue if B>2*R and B>2*G. However, my question is not so much about how to change the pixel color of an image in power point, but whether it is possible to do so. – JN_2605 Nov 21 '22 at 13:21
  • 1
    It's trivial to locate picture shapes by checking each shape's .Type rather than trusting it's .Name property. But as to the "what is blue" and "why do you want to do this", wouldn't it be better to suggest a *method* for looking at the color of each pixel and changing it if desired? That would answer OP's question. – Steve Rindsberg Nov 21 '22 at 15:20
  • I find this questions super interesting, I hope you will get an answer. Maybe a start could be here: https://learn.microsoft.com/en-us/office/vba/api/publisher.pictureformat.colormodel , here https://learn.microsoft.com/en-us/office/vba/api/publisher.pictureformat.colorsinpalette and here https://learn.microsoft.com/en-us/office/vba/api/publisher.pictureformat.istruecolor Maybe a bit off topic, there could be something interesting here, too: https://www.aeternusconsulting.com/great-art-pixelated-with-excel-vba/ – Oran G. Utan Nov 21 '22 at 18:45
  • I also found this https://stackoverflow.com/a/39859252/18247317, the second comment is about looping through the whole picture And this looks interesting, too: https://stackoverflow.com/questions/61580638/vba-get-colour-of-pixel – Oran G. Utan Nov 21 '22 at 19:02

0 Answers0