Fillpath method transparency cannot be set,

Using the fillpath method, transparency cannot be set, and regardless of how much transparency is set, the transparency of the filled color is always 1.0

                     waveformPath.lineTo(width, height); 
                     waveformPath.lineTo(0.0f, height); 
                     waveformPath.closeSubPath();
              
                     g.setColour(juce::Colour::fromFloatRGBA(1.0f, 0.0f, 0.0f, 0.5f)); // 半透明红色
                     g.fillPath(waveformPath);

Could you post a minimum test case that can be built? The following code works completely fine on my computer:
2024-01-22 07.56.21

    void MainPanel::paint(juce::Graphics &g) {
        juce::ignoreUnused(g);
        juce::Path path;
        const auto bound = getLocalBounds().toFloat();
        path.startNewSubPath(bound.getTopLeft());
        path.lineTo(bound.getTopRight());
        path.lineTo(bound.getBottomRight());
        path.closeSubPath();

        g.setColour(juce::Colour::fromFloatRGBA(1.0f, 0.0f, 0.0f, 0.5f)); // 半透明红色
        g.fillPath(path);
    }
            juce::Path waveformPath;
            

            waveformPath.startNewSubPath(0.0f, juce::jmap(scopeData[0], 0.0f, 1.0f, height, 0.0f));
            
   

            for (int i = 1; i < scopeSize; ++i)
            {
                float x = juce::jmap((float)i, 0.0f, (float)(scopeSize - 1), 0.0f, width);
                float y = juce::jmap(scopeData[i], 0.0f, 1.0f, height, 0.0f);
                waveformPath.lineTo(x, y);
            }
 
      
            waveformPath.lineTo(width, height); 
            waveformPath.lineTo(0.0f, height); 
            waveformPath.closeSubPath(); 
            
 
            g.setColour(juce::Colour::fromFloatRGBA(1.0f, 0.0f, 0.0f, 0.5f)); // 半透明红色
            g.fillPath(waveformPath);

I am using this method to display spectrograms, and every time I call repaint(), I don’t know if it is related to this. The only problem now is that I cannot display a color with transparency. No matter how I modify it, this color always appears

Here is the complete code

void paint (juce::Graphics& g)
    {
        
        for (int i = 1; i < scopeSize; ++i)
        {
                        auto bounds = getLocalBounds().toFloat();
                        float const width  = bounds.getWidth();
                        float const height = bounds.getHeight();
    
            juce::Path waveformPath;
            
        
            waveformPath.startNewSubPath(0.0f, juce::jmap(scopeData[0], 0.0f, 1.0f, height, 0.0f));
            
            

            for (int i = 1; i < scopeSize; ++i)
            {
                float x = juce::jmap((float)i, 0.0f, (float)(scopeSize - 1), 0.0f, width);
                float y = juce::jmap(scopeData[i], 0.0f, 1.0f, height, 0.0f);
                waveformPath.lineTo(x, y);
            }
 
         
            waveformPath.lineTo(width, height); 
            waveformPath.lineTo(0.0f, height); 
            waveformPath.closeSubPath(); 
            
            g.setColour(juce::Colour::fromFloatRGBA(1.0f, 0.0f, 0.0f, 0.5f)); 
            g.fillPath(waveformPath);
        

        
    }
    
}

@rebbur master ! save me! :smiling_face_with_three_hearts:

@ zsliu98 master ! save me! :smiling_face_with_three_hearts:

The whole body of your paint() runs in a outer loop of scopeSize iterations.
With every run of that outer loop, you draw your scope at 50% alpha, but you are drawing it scopeSize times, one over the other, and the results comes out as opaque if scopeSize is large enough.

It’s like painting on a wall with a brush over and over again over the same spot, eventually the spot ends up being opaque even if a single pass of the brush were to leave it semi-transparent.

I think you should remove the whole outer loop altogether, probably that was left there by a copy/paste (also because the index i is not used anywhere else aside from the inner loop, which declares its own i anyway which shadows the outer i)

thank you very mush,is solution!!!