Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    May 2013
    Posts
    45
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Modifiy Depth/Visible Priority of Image

    drawImage(whatever,0,0);
    drawImage(something,0,0);

    I want whatever to be above something even though I drew it after. Kinda like a z component or a depth component like many other languages have.

    Ex:
    whatever.z = 10;
    something.z = 0;

    Is it possible with JS?

    Thanks.

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    You have something called the z-index, which is a style property, it can be controlled by javascript, like any other style property. If x and y are the horizontal and vertical order, then z is the 'stacking order'. That's where it gets its name.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    But I don't know that this works with drawImage( ) on a canvas, DrDOS.

    Canvas drawing is done by simply dropping pixels into what is essentially a single image. So any pixels drooped later will always overwrite the ones dropped earlier.

    In short, I believe the answer to the question is: It can't be done with drawImage.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    you can draw to a different context and stack them in any order at a later point.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #5
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    Quote Originally Posted by Old Pedant View Post
    But I don't know that this works with drawImage( ) on a canvas, DrDOS.

    Canvas drawing is done by simply dropping pixels into what is essentially a single image. So any pixels drooped later will always overwrite the ones dropped earlier.

    In short, I believe the answer to the question is: It can't be done with drawImage.
    I didn't see that he was referring to Canvas, in that case it works the same as in .svg, for drop shadow in either case, the shadow text would be written first, the fill color would be written next, on the page, and slightly displaced. In fact on my website, see my siggy, I've just thought of a way for people to preview the outline and dropshadow modes of text using an .svg
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Quote Originally Posted by rnd me View Post
    you can draw to a different context and stack them in any order at a later point.
    Yes, and if the background or the front image is transparent then I would assume you could get the effect you are after.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •