EditableImage

Visualizza obsoleti

EditableImage allows for the runtime creation and manipulation of images. It can be created from an existing image using AssetService:CreateEditableImageAsync(), or a blank EditableImage can be created with Instance.new(). EditableImage overrides the image/texture displayed when parented to certain objects as follows:

The EditableImage coordinate system is relative to the top left of the image:

  • Top-left: (0, 0)
  • Bottom-right: (Size.X - 1, Size.Y - 1)

When publishing an object via AssetService:PromptCreateAssetAsync() that has a property overridden by a child EditableImage, the editable image will be published as an image and the overridden property will be set to the new asset ID.

Sommario

Proprietà

Metodi

Proprietà

Lettura Parallela

Size of the EditableImage in pixels. The maximum size is 1024×1024 and attempting to set this property to a larger size will cause it to be clamped at 1024.

Setting this property changes the canvas size of the editable image but does not resize the contents. If changing to a larger size, new pixels will be set to an RGBA value of [0, 0, 0, 0]. If changing to a smaller size, existing pixels will be cropped. Consider using Resize() to update the contents while changing the size.

Metodi

Copies a subregion of the EditableImage to a new EditableImage.

Parametri

min: Vector2

Top-left corner of the region to copy, with (0, 0) being the top-left corner of the source image.

max: Vector2

Bottom-right corner of the region to copy, exclusive. For example, a max of EditableImage.Size would end the subregion at the bottom and right edges of the source image.


Restituzioni

A new EditableImage containing the specified subregion.

Crop

void

Crops the EditableImage to the specified subregion.

Parametri

min: Vector2

Top-left corner of the region to crop to, with (0, 0) being the top-left corner of the source image.

max: Vector2

Bottom-right corner of the region to crop to, exclusive. For example, a max of EditableImage.Size would end the subregion at the bottom and right edges of the source image.


Restituzioni

void

DrawCircle

void

Draws a circle at the specified point on the EditableImage. If the circle is semi-transparent, it will be blended with the pixels behind it using source over blending.

Parametri

center: Vector2

Center of the circle, relative to the top-left corner of the EditableImage. Positions outside the canvas bounds are allowed.

radius: number

Radius of the circle in pixels.

color: Color3

Color of the circle.

transparency: number

Transparency of the circle with 0 being fully opaque and 1 being fully transparent.


Restituzioni

void

DrawImage

void

Draws another EditableImage into this EditableImage at the given position. Positions outside the canvas bounds are allowed such that only part of the new image is drawn.

Parametri

position: Vector2

Position at which the top-left corner of the added image will be drawn.

The EditableImage to draw into this EditableImage.

How the pixels of the source image should be blended with the pixels of the added image.


Restituzioni

void

DrawLine

void

Draws an anti-aliased line on the EditableImage one pixel thick between the two provided points.

Parametri

Start point of the line.

End point of the line.

color: Color3

Color of the line.

transparency: number

Transparency of the line.


Restituzioni

void

DrawProjectionImage

void

Parametri

projection: Dictionary
brushConfig: Dictionary

Restituzioni

void

DrawRectangle

void

Draws a rectangle on the EditableImage of the given size at the given top-left position.

Parametri

position: Vector2

Position of the top-left of the rectangle. Unlike other drawing methods, this cannot be outside the canvas bounds of the EditableImage.

size: Vector2

Size of the rectangle to draw, in pixels.

color: Color3

Color of the rectangle.

transparency: number

Transparency of the rectangle.


Restituzioni

void

ReadPixels

Scrivi Parallelo

Reads a rectangular region of pixels. The pixels will be returned as a flat array where each pixel is represented by four numbers between 0 and 1 (red, green, blue, and alpha respectively). Note that this method uses alpha instead of transparency, unlike the EditableImage drawing methods.

Parametri

position: Vector2

Top-left corner of the rectangular region of pixels to read.

size: Vector2

Size of the rectangular region of pixels to read.


Restituzioni

Flat array where each pixel is represented by four numbers between 0 and 1 (red, green, blue, and alpha respectively). The length of the array can be calculated as Size.X * Size.Y * 4.

Campioni di codice

EditableImage:ReadPixels()

local editableImage = Instance.new("EditableImage")
local pixels = editableImage:ReadPixels(Vector2.zero, Vector2.new(2, 1))
local color1 = Color3.new(pixels[1], pixels[2], pixels[3])
local transparency1 = 1 - pixels[4]
local color2 = Color3.new(pixels[5], pixels[6], pixels[7])
local transparency2 = 1 - pixels[8]
local averageColor = color1:Lerp(color2, 0.5)
local averageTransparency = (transparency1 + transparency2) / 2
local part = Instance.new("Part")
part.Color = averageColor
part.Transparency = averageTransparency
part.Parent = workspace

Resize

void

Resizes the contents and canvas of the EditableImage using bilinear interpolation. Max allowed size is 1024×1024.

Parametri

size: Vector2

New size of the EditableImage.


Restituzioni

void

Rotate

void

Rotates the EditableImage around its center using bilinear interpolation.

Parametri

degrees: number

Degrees to rotate the image.

changeSize: bool

Whether the size of the canvas should be updated.


Restituzioni

void

WritePixels

void

Writes a rectangular region of pixels into the EditableImage. The pixels are provided as a flat array where each pixel is represented by four numbers between 0 and 1 (red, green, blue, and alpha respectively). Note that this method uses alpha instead of transparency, unlike other EditableImage drawing methods.

Parametri

position: Vector2

Top-left corner of the rectangular region to draw the pixels into.

size: Vector2

Size of the rectangular region of pixels to write.

pixels: Array

Flat array where each pixel is represented by four numbers between 0 and 1 (red, green, blue, and alpha respectively). The length of the array should be Size.X * Size.Y * 4.


Restituzioni

void

Campioni di codice

EditableImage:WritePixels()

local editableImage = Instance.new("EditableImage")
local pixels = editableImage:ReadPixels(Vector2.zero, editableImage.Size)
for i = 1, editableImage.Size.X * editableImage.Size.Y do
local pixelIndex = 1 + ((i - 1) * 4)
pixels[pixelIndex] = 1 - pixels[pixelIndex]
pixels[pixelIndex + 1] = 1 - pixels[pixelIndex + 1]
pixels[pixelIndex + 2] = 1 - pixels[pixelIndex + 2]
end
editableImage:WritePixels(Vector2.zero, editableImage.Size, pixels)

Eventi