Pixelating an Image

BakutaBakuta Posts: 3Member

Hello all!
I'm currently running into a problem while attempting to pixelate an image in GDScript.
My current process is loading an image, resizing the image along with Image.INTERPOLATE_NEARESTto my desired pixel image size eg (32x32 pixels). However, after the resize function is called, the image's width and height have not changed and the image seems to remain the same.
Here is the example code I'm using

var image := Image.new()
image.load("path/to/image")
image.lock()
image.resize(32, 32, Image.INTERPOLATE_NEAREST)
image.unlock()

Any help at all would be greatly appreciated!


Tags :

Best Answer

  • BakutaBakuta Posts: 3
    Accepted Answer

    SOLVED:

    You cannot resize an image while it is locked!
    If you move the resize function before the lock, all works as intended!

Answers

  • BakutaBakuta Posts: 3Member
    Accepted Answer

    SOLVED:

    You cannot resize an image while it is locked!
    If you move the resize function before the lock, all works as intended!

  • CalinouCalinou Posts: 409Admin Godot Developer

    Note that locking/unlocking Images before reading/editing their pixels will no longer be required in Godot 4.0.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file