Last Login:
July 08, 2017


User Profile

Hits: 3,048
Joined September 19, 2012

buffer_getpixel for Game Maker Studio
Posted on May 09, 2017 at 14:09

Are you a game maker user?
Need a faster surface_getpixel?
You come to the right place!​

This asset comes with a small list of scripts that will help you get a pixel color super fast and its totally free.​

How to use each command:

buffer_getpixel_begin(surface) = creates the buffer for checking using a specified surface id
(or surface drawing) and returns you a buffer index.
(NOTE: application_surface only picks the regular Draw events;
not the GUI events.)
If your surface image is static, you can set it to create event,
otherwise, set it in the event that you will get the pixel.

buffer_getpixel(ind,x,y,width,height) = Gets the RGB of a pixel within the specified buffer id (surface).

buffer_getpixel_ext(ind,x,y,width,height) = Gets the RGBA of a pixel within the specified buffer id.

buffer_getpixel_r(ind x,y,width,height) = Gets the Red value of a pixel

buffer_getpixel_g(ind x,y,width,height) = Gets the Green value of a pixel

buffer_getpixel_b(ind x,y,width,height) = Gets the Blue value of a pixel

buffer_getpixel_a(ind x,y,width,height) = Gets the Alpha value of a pixel


The file comes with the scripts and a demonstration of how it works (for dynamic images);

In case your image does not need to update the drawing at all, here's an example on how it works for static images (performance is more noticeable from this):

var ss = surface_create(800,450);

WIDE = surface_get_width(ss);
HIGH = surface_get_height(ss);

buff = buffer_getpixel_begin(ss);
//DRAW EVENT (or any other event)
var pixel = buffer_getpixel(buff,16,16,WIDE,HIGH);



Try it out if you like and give feedback.
Any problems, doubts, questions, do reply back if you like!

surface_getpixel is notoriously slow, so it's great to see a functional replacement!
Posted by Requiem May 10, 2017 11:27 - 4.6 months ago
| [#1]

That's really awesome. Thanks for sharing this, I'll have to bookmark it and in case I have a use case.
Posted by twisterghost May 11, 2017 7:35 - 4.6 months ago
| [#2]

Do you have any benchmarking between this and the native equivalent?
Posted by twisterghost May 11, 2017 10:13 - 4.6 months ago
| [#3]

I would have figured after 13 years since GM6 came out, they would have made surface_getpixel faster.
Posted by Aistarin May 11, 2017 10:15 - 4.6 months ago
| [#4]

Any chance you'll upload it to somewhere other than the marketplace?
Posted by Mairu May 11, 2017 21:48 - 4.6 months ago
| [#5]

Thanks for all the feedbacks, everyone! :)

Mairu, is it because you dont have an account in the marketplace? If thats the case I would consider giving a mirror link. Although making an account on that site is really easy and simple thing to do. Dont see why you wont consider trying. Anyway here are the two mirror links.

(GMS1): https://www.dropbox.com/s/f05sshi6rzae7l1/buffer_getpix.gmz?dl=0
(GMS2): https://www.dropbox.com/s/zdymfm931p16pc3/buffer_getpix.yyz?dl=0
Posted by Misu May 14, 2017 19:32 - 4.5 months ago
| [#6]

I am interested in it, but I don't need it right now. I find it easier to manage files on my computer than my marketplace library so the less I add to it the better. Thank you for the alternative links!
Posted by Mairu May 16, 2017 7:43 - 4.4 months ago
| [#7]

Recent Activity
Active Users (0)