It takes in a table and reads it from top left, top-bottom. The table is equal to the size of the canvas (x*y) and has 4 values for each pixel, meaning a 10x10 image has 400 indexes in the table.
EditableImage:WritePixels(Vector2.new(0,0),Vector2.new(2,2),{255,0,0,0,200,255,0,0.5,255,255,255,0,0,0,0,1}) paints the 4 pixels in the top left corner.
The table is read in fours, so {Red, Green, Blue, Transparency}.
its like @theseformasentence said, but the color values must be between 0 and 1, the same way you would use Color3.new(), and the last one is actually alpha, not transparency
EditableImage:WritePixels(
Vector2.new(123, 234), -- position
Vector2.one, -- size
{
1, -- r
0, -- g
0, -- b
1, -- alpha, 0 = fully transparent
}
)
You specify the top left corner as your position, and the size of the rectangle you want to fill. Each 4 numbers in the array represent the r, g, b and alpha values of each pixel, left to right, row by row inside the mentioned rectangle.
Since it’s an array with 4 numbers, its the same as filling only one pixel.
local pixels = table.create(dyi.Size.X*dyi.Size.Y*4, 1); -- create a blank white rectangle
// Replace the values with (1,1,1,0)
for x=0, dyi.Size.X-1 do
for y=0, dyi.Size.Y-1 do
local i0 = y * dyi.Size.X + x + 1; -- y * horizontal size + x + 1
pixels[i0+0] = 1;
pixels[i0+1] = 1;
pixels[i0+2] = 1;
pixels[i0+3] = 0;
end
end
image:WritePixels(
Vector2.new(0, 0),
dyi.Size,
pixels
)
Also, setting alpha to 0 will make it transparent, so you might want to replace it with 1.
local UI = script.Parent
local DYI = Instance.new("EditableImage",UI.ImageLabel)
for x = 1,DYI.Size.X do
for y = 1,DYI.Size.Y do
DYI:WritePixels(Vector2.new(x, y),Vector2.one, {1,0,0,1})
game:GetService('RunService').RenderStepped:Wait()
end
end
Because color3 is expensive to create in comparison. It’s a method call that creates a userdata associated with an array of 3 floats. 3 numbers are just 3 numbers. It gets expensive fast when a 1000x1000 image would require a million color3s, and that wouldn’t even fill an average laptop’s resolution.
so i used your script and it kinda worked but not what way i wanted it to
local UI = script.Parent
local DYI = Instance.new("EditableImage",UI.ImageLabel)
local pixels = table.create(DYI.Size.X*DYI.Size.Y*4, 1)
for x=0, DYI.Size.X-1 do
for y=0, DYI.Size.Y do
local i0 = y * DYI.Size.X + x + 1;
pixels[i0+0] = 1;
pixels[i0+1] = 1;
pixels[i0+2] = 0;
pixels[i0+3] = 1;
end
end
DYI:WritePixels(Vector2.new(0, 0),DYI.Size,pixels)