Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Image manipulation

edited January 2014 in Questions Posts: 63

Hi if anyone could help I'd be very grateful. Last time I did a program was on a zx spectrum over 30 years ago. Anyway, got Codea last week and loving it.
Q.1 Is there anyway to take a snap shot of a defined area of the screen and use that as an image? As this would be a last resort to solve Q.2
Q.2 The sprite function allows me to resize a photograph imported from "Documents" whilst putting it on screen, but I want to resize, overlay another image from documents and then save this as a new image to documents for use later on...all obviously without it being shown. I can't seem to achieve this using any combination of image commands, setContext and sprite.
Many thanks

Tagged:

Comments

  • edited January 2014 Posts: 547

    @TheAbstractMan
    Q1. Instead of writing to the screen, you can do

    function setup()
        screen = image(WIDTH, HEIGHT)
    end
    

    this would create and image to draw on, you can then do

    function draw()
        -- this puts the drawing area to the screen image
        setContext(screen)
        -- all the draw code
    
        -- this resets the canvas to draw on the the ipad screen
        setContext()
    
        -- to make sure the image renders on the right place
        spriteMode(CENTER)
        sprite(screen, WIDTH/2, HEIGHT/2)
    
    end
    

    if you then want to capture a certain area, you can do

        capturedImage = screen:copy(x, y, width, height)
        -- x and y are the coordinates of the area you want to capture, width and height speak for themselves
    
  • Wonderful - exactly what I was attempting...and I can see where I went wrong. Many thanks.

  • IgnatzIgnatz Mod
    Posts: 5,396

    @TheAbstractMan - there are quite a few people in this forum of your vintage, so don't feel out of place.

    Welcome.

  • edited January 2014 Posts: 63

    Cheers, and thanks for your intro manuals etc on the web - I read through them all. Very helpful.

  • One further question: obviously it would slow the program down but is it possible to have the above code running simultaneously with what's going on on screen so in effect you have a running screen and a virtual copy of the screen?

  • edited January 2014 Posts: 547

    @TheAbstractMan what do you mean exactly? Like have a virtual copy of the current frame?

    I think you can just store it into a second var like

    virtual = screen
    
  • Posts: 371

    @TheAbstractMan, sure, just add sprite(screen, WIDTH / 2, HEIGHT /2) (as @stevon8ter said) at the end of draw

  • Yes a virtual copy of the frame...my thought is that if we create a virtual canvas which is what you are doing with the screen = image (......) bit at the top. We are then drawing or whatever on that canvas. Whatever is drawn on the canvas we can then pass to the real screen, which is what your code is doing with sprite(screen.....) ...I guess I'm still on about my original question 1 above. I.e. reversing this process and simply capturing the current real screen as an image...as if this can be done then you have in effect a virtual copy which at any point can be manipulated independently.

  • @TheAbstractMan

    well the screen image doesn't change, (unless you change it, as done by overdrawing it in draw)

    so you can basicly just save it into another var when you need it to capture the screen

Sign In or Register to comment.