# "Copy" alpha channel from a memory image to another

**URL:** <https://forum.juce.com/t/copy-alpha-channel-from-a-memory-image-to-another/13592>\
**Category:** General JUCE discussion\
**Created:** [September 19, 2014, 8:25pm UTC](https://forum.juce.com/t/copy-alpha-channel-from-a-memory-image-to-another/13592 "2014-09-19T20:25:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcyuan](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@jcyuan](https://forum.juce.com/u/jcyuan)\
**Post date:** [September 19, 2014, 8:25pm UTC](https://forum.juce.com/t/copy-alpha-channel-from-a-memory-image-to-another/13592/1 "2014-09-19T20:25:24Z")

</div>

but i got wrong result.

my target is draw an image with some specified shap masked.

my steps:

1, create a pie shape:

```auto
Path arc;
static const float FROMARC = 270.0f * RADIAN;
arc.addPieSegment(0, 0, width, height + 5.0f, FROMARC, FROMARC + m_fCurArcAngle, 0.0f);
```

2, update the “canvas”:

```auto
m_pathCache->clear(m_pathCache->getBounds()); //clear then now it's transparent
juce::Graphics ig(*m_pathCache);
ig.setColour(Colour(0xff000000)); /draw the pie with black to the memory image
ig.fillPath(arc);
```

3, final step to apply the memory ‘shape’ image to the display image:

```auto
FillType ft(*m_pathCache, AffineTransform::identity);
g.setFillType(ft);
g.drawImageAt(m_imgMaskBg, 0, 0, true); //final display
```

but… on my screen, the result is a black pie!  
something wrong??  
i need help!! guys~

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 20, 2014, 1:35pm UTC](https://forum.juce.com/t/copy-alpha-channel-from-a-memory-image-to-another/13592/2 "2014-09-20T13:35:32Z")

</div>

Maybe you should&nbsp;use Graphics::reduceClipRegion to clip to your image alpha?

---

<div class="post-metadata">

**Author:** ![jcyuan](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@jcyuan](https://forum.juce.com/u/jcyuan)\
**Post date:** [September 21, 2014, 3:57am UTC](https://forum.juce.com/t/copy-alpha-channel-from-a-memory-image-to-another/13592/3 "2014-09-21T03:57:02Z")

</div>

the region has same size and coords with the display image,&nbsp;

so i think no&nbsp;need to call this API?

i just made a picture to explain what i want, and my code at above as you see what:

arc -\> the black pie path

m\_pathCache -\> the bitmpa cache&nbsp;to draw the pie path

m\_imgMaskBg -\> the original display image (and sould be the correct result to display)

![](http://kaernuo.com/images/tpl/def/case.jpg)

thanks for your so amazing framework jules!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 21, 2014, 10:01am UTC](https://forum.juce.com/t/copy-alpha-channel-from-a-memory-image-to-another/13592/4 "2014-09-21T10:01:57Z")

</div>

Right, so clip to the path you want with reduceClipRegion, then just draw the entire image.

(I don't recommend using images though - this kind of thing is better done with vector graphics)

---

<div class="post-metadata">

**Author:** ![jcyuan](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@jcyuan](https://forum.juce.com/u/jcyuan)\
**Post date:** [September 21, 2014, 2:56pm UTC](https://forum.juce.com/t/copy-alpha-channel-from-a-memory-image-to-another/13592/5 "2014-09-21T14:56:14Z")

</div>

this really impressed me!!

i thought that clip region only could apply square shape....

now it works very well, the memory bitmp is unnecessary.

many many&nbsp;thanks jules.
