# Strange behaviour in Image::getClippedImage?

**URL:** <https://forum.juce.com/t/strange-behaviour-in-image-getclippedimage/14630>\
**Category:** General JUCE discussion\
**Created:** [April 17, 2015, 9:25am UTC](https://forum.juce.com/t/strange-behaviour-in-image-getclippedimage/14630 "2015-04-17T09:25:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tim\_is\_tof](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@tim\_is\_tof](https://forum.juce.com/u/tim_is_tof)\
**Post date:** [April 17, 2015, 9:25am UTC](https://forum.juce.com/t/strange-behaviour-in-image-getclippedimage/14630/1 "2015-04-17T09:25:59Z")

</div>

Hi,

It seems that when calling Image::duplicateIfShared() on an image aquired trough Image::getClippedImage(), &nbsp;the clipped image isn't duplicated.

I have the following code snippet from my component's paint routine:

```
Image activeImage = image.getClippedImage(area);
activeImage.duplicateIfShared();

// this is a custom function
multiplyImageWithColour( activeImage, avAudioLightColour.withBrightness(1.f).withAlpha(1.f));

g.drawImage(activeImage,
            (int)(start * image.getWidth()), 0,
            (int)((end - start) * getWidth()),
            getHeight(), 0, 0, activeImage.getWidth(), activeImage.getHeight());
```

The resulting image gets drawn darker and darker, because the image gets recylced and "coloured" over and over.

This doesn't happen if I create activeImage like so:

```
Image activeImage = image;
activeImage.duplicateIfShared();
activeImage = activeImage.getClippedImage(area);
```

Is this a bug?

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [April 19, 2015, 12:12pm UTC](https://forum.juce.com/t/strange-behaviour-in-image-getclippedimage/14630/2 "2015-04-19T12:12:36Z")

</div>

Hi tim\_is\_tof,

you are right: there seems to be a bug in the way duplicateIfShared() handles the case when the pixel data is of type SubsectionPixelData. I've implemented a fix for this which I've&nbsp;sent&nbsp;over to Jules for his approval.

Thanks for reporting this!

Fabian

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [April 22, 2015, 4:39pm UTC](https://forum.juce.com/t/strange-behaviour-in-image-getclippedimage/14630/3 "2015-04-22T16:39:43Z")

</div>

Should be in newest tip now!
