Hello there! I rarely do stuff in Roblox Studio nowadays, however, I wanted to experiment with the EditableImage, which I have done before but how they work has changed a little since last time.
To the point:
When I attempt to overwrite the pixels of an EditableImage, then the colours aren’t represented accurately in the image. Although the colours are close most of the time, they are often a bit off (darker / lighter than the inserted value). What I would like to achieve is to completely overwrite pixels and have them display colour accurately.
What have I tried?:
Even though using ‘Overwrite’ (2) as the ImageCombineType makes the most sense I decided to test the ‘Add’ (3) (not what I want based on description) value, which works great for the first iteration or two, then it will eventually turn into pure white.
Video (the square to the left is a frame displaying the expected colour):
Forgot to post the code, here it is (image is 640x480, VGA)
local RunService = game:GetService("RunService")
local AssetService = game:GetService("AssetService")
local IL = script.Parent
local Img = AssetService:CreateEditableImage({Size = IL.AbsoluteSize})
local Real = script.Parent.Parent.Real
IL.ImageContent = Content.fromObject(Img)
local function SetPixel(x,y,c,a)
local p = Vector2.new(x,y)
Img:DrawLine(p,p,c,a,Enum.ImageCombineType.Add)
end
local function SetColor(r,g,b,c)
for x = 0,Img.Size.X-1 do
for y = 0,Img.Size.Y-1 do
SetPixel(x,y,c,0)
end
RunService.RenderStepped:Wait()
end
end
while true do
local r = math.random(0,255)
local g = math.random(0,255)
local b = math.random(0,255)
local c = Color3.fromRGB(r,g,b)
print(r,g,b)
Real.BackgroundColor3 = c
SetColor(r,g,b,c)
end
You’re using Enum.ImageCombineType.Add, this essentially adds the RGB values of both pixel color values together. The enum value you should’ve been actually using was Enum.ImageCombineType.Overwrite.
That just happened to be left inside there when I tried using ‘Add’ instead of ‘Overwrite’. The latter is used in the video, if you use ‘Add’, then (in the video) the EditableImage would have become completely white within the first few iterations.
DrawLine used to work great to write single pixels, however apparently that’s not the case anymore, since they made quite a bit of changes to the EditableImage since the last time I used it.
DrawRectangle works great now.