# If hovering over? pic paste, rotate friendly (detects if over transparent parts of img)

**URL:** https://discourse.processing.org/t/if-hovering-over-pic-paste-rotate-friendly-detects-if-over-transparent-parts-of-img/10662
**Category:** Coding Questions
**Created:** [April 26, 2019, 2:05pm UTC](https://discourse.processing.org/t/if-hovering-over-pic-paste-rotate-friendly-detects-if-over-transparent-parts-of-img/10662 "2019-04-26T14:05:18Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [April 26, 2019, 2:05pm UTC](https://discourse.processing.org/t/if-hovering-over-pic-paste-rotate-friendly-detects-if-over-transparent-parts-of-img/10662/1 "2019-04-26T14:05:18Z")

</div>

Hi, i’ve been wondering how to detect if mouse (or just X and Y cords) is hovering over an image, and if the image is transparent at x y it isnt hovering over. So if you r hovering over transparent part of img it returns false. That would be a lot, but i’d ask if you could help with some rotate stuff, so same, but img can rotate? Well by that point it would be easier if you would just input img, and a function would: paste img, rotate canvas, by point x and y, so you wouldnt need to find all the other stuff.

Thanks!

---

<div class="post-metadata">

### Author: ![DongKingKong0](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/dongkingkong0/32/960_2.png) [@DongKingKong0](https://discourse.processing.org/u/DongKingKong0)
#### Post date: [April 28, 2019, 1:02pm UTC](https://discourse.processing.org/t/if-hovering-over-pic-paste-rotate-friendly-detects-if-over-transparent-parts-of-img/10662/2 "2019-04-28T13:02:53Z")

</div>

Detecting transparent pixels depends on what you consider “transparent”.  
Do you mean pixels with an alpha value of `0` (i.e. full transparency) or just less than `255` (no transparency at all)?

---

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [April 30, 2019, 10:03am UTC](https://discourse.processing.org/t/if-hovering-over-pic-paste-rotate-friendly-detects-if-over-transparent-parts-of-img/10662/3 "2019-04-30T10:03:15Z")

</div>

well… maby below value? maby int transparentValue = 100; if \< 100 than its considered transparent

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [April 30, 2019, 1:27pm UTC](https://discourse.processing.org/t/if-hovering-over-pic-paste-rotate-friendly-detects-if-over-transparent-parts-of-img/10662/4 "2019-04-30T13:27:17Z")

</div>

You can use get()

When the result color is simply similar background color, it’s transparent

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [May 2, 2019, 2:43am UTC](https://discourse.processing.org/t/if-hovering-over-pic-paste-rotate-friendly-detects-if-over-transparent-parts-of-img/10662/5 "2019-05-02T02:43:57Z")

</div>

If the image being drawn on a PGraphics then you can check for the alpha value of the pixel under the mouse directly with `alpha()`: [https://processing.org/reference/alpha\_.html](https://processing.org/reference/alpha_.html)

Note that the main canvas doesn’t support alpha, so you cannot measure alpha directly after a transparent image has been composited onto it – only the background color to the extent that it shows through. If you only have an image that never uses the same color as your canvas background – and only has pixels that are either 100% transparent or 100% opaque – then checking for the background works well. If you have partial transparency or can’t guarantee that image colors won’t match the background then the PGraphics method is more flexible and reliable.
