vydd / sketch

A Common Lisp framework for the creation of electronic art, visual design, game prototyping, game making, computer graphics, exploration of human-computer interaction, and more.
MIT License
1.39k stars 67 forks source link

Question: Getting dimensions and pixels of loaded image #73

Closed emenel closed 1 year ago

emenel commented 1 year ago

Hi!

I'm just started to experiment with Sketch and love the approach. I can't find documentation for working with images, so maybe I'm missing something?

Is there a way to load an image inside a sketch (I'm using load-resource at the moment) and then get its dimensions to use inside the sketch?

And is there a way to work with the pixel data from the image (like in Processing or similar)?

Thank you!

Kevinpgalligan commented 1 year ago

I haven't tried it, but this class has accessor methods image-width and image-height, you could try calling those on the image resource!

https://github.com/vydd/sketch/blob/master/src/resources.lisp#L15-L18

It's not in the documentation, but a canvas object has recently been added to the API that lets you address individual pixels. Here's an example that uses it:

https://github.com/vydd/sketch/blob/master/examples/stars.lisp

Kevinpgalligan commented 1 year ago

I just confirmed that image-width and image-height work, but they're not exported from the sketch package, so you'd have to use sketch::image-width to access them.

emenel commented 1 year ago

Thanks so much @Kevinpgalligan. I had been away, but just had a moment to try this and it seems to work like I wanted. Thanks again!