EditableImage

แสดงที่เลิกใช้งานแล้ว

*เนื้อหานี้จะพร้อมใช้งานในภาษาที่คุณเลือกในเร็วๆ นี้

ไม่สามารถสร้าง

EditableImage allows for the runtime creation and manipulation of images.

To create a blank EditableImage, use AssetService:CreateEditableImage(). To create an EditableImage from an existing image, use AssetService:CreateEditableImageAsync().

EditableImage can be used in any Content property which takes an image, such as ImageLabel.ImageContent or MeshPart.TextureContent. This is done by setting the content property to Content.fromObject(editableImage).

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 you use AssetService:PromptCreateAssetAsync() to publish an object that has a Content property which references an EditableImage, the editable image is published as an image and the property is set to a new asset ID.

Enabling EditableImage for Published Experiences

For security purposes, using EditableImage fails by default for published experiences. To enable the use of EditableImage, you must be 13+ age verified and ID verified. After you are verified, open Studio. Select File > Game Settings > Security and enable the Allow Mesh & Image APIs toggle. Remember to review the Terms of Use before enabling the toggle.

Permissions

To prevent misuse, AssetService:CreateEditableImageAsync() only allows you to load and edit image assets:

  • That are owned by the creator of the experience (if the experience is owned by an individual).
  • That are owned by a group (if the experience is owned by the group).
  • That are owned by the logged in Studio user (if the place file has not yet been saved or published to Roblox).

The APIs throw an error if they are used to load an asset that does not meet the criteria above.

สรุป

คุณสมบัติ

  • อ่านอย่างเดียว
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน

    Size of the EditableImage in pixels.

วิธีการ

คุณสมบัติ

อ่านอย่างเดียว
ไม่ซ้ำ
อ่านพร้อมๆ กัน

Size of the EditableImage in pixels. The maximum size is 1024×1024. An EditableImage cannot be resized; this property is read-only. In order to resize or crop an image, create a new EditableImage and use DrawImageTransformed() to transfer the contents; then call Destroy().

วิธีการ

Destroy

void

Destroys the contents of the image, immediately reclaiming used memory.


ส่งค่ากลับ

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.

พารามิเตอร์

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.

How the pixels of the source image are blended with the pixels of the added image.


ส่งค่ากลับ

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.

พารามิเตอร์

position: Vector2

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

image: Object

The EditableImage to draw into this EditableImage.

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


ส่งค่ากลับ

void

DrawImageProjected

void

พารามิเตอร์

mesh: Object
projection: Dictionary
brushConfig: Dictionary

ส่งค่ากลับ

void

DrawImageTransformed

void

This method lets you draw an EditableImage into this EditableImage with transformations applied, such as scaling and rotation. The position parameter specifies where the pivot point of the source image will be placed on this image after transformations. Positions outside the canvas bounds are allowed such that only part of the new image is drawn.

พารามิเตอร์

position: Vector2

Position in pixels where the pivot point of the source image will be placed on this image.

scale: Vector2

Scaling factors for the source image along the X and Y axes.

rotation: number

The rotation angle in degrees, applied around the pivot point of the source image.

image: Object

The source EditableImage to be drawn into this image.

options: Dictionary

Optional dictionary for additional configuration:

  • CombineType: Specifies how the pixels of the source image blend with those of the destination. Default is Enum.ImageCombineType.AlphaBlend.
  • SamplingMode: Specifies the sampling method (e.g. Default for bilinear or Pixelated for nearest neighbor). Default is Enum.ResamplerMode.Default.
  • PivotPoint: Specifies the pivot point within the source image for scaling and rotation. Default is the center of the source image (i.e. Image.Size / 2).

ส่งค่ากลับ

void

ตัวอย่างโค้ด

EditableImage:DrawImageTransformed()

local AssetService = game:GetService("AssetService")
-- Example of drawing a rotated and scaled image onto another EditableImage
local srcImage = AssetService:CreateEditableImage({ Size = Vector2.new(256, 256) })
local dstImage = AssetService:CreateEditableImage({ Size = Vector2.new(512, 512) })
-- Drawing with a rotation of 45 degrees, scaling by 2x, and placing at (100, 100)
dstImage:DrawImageTransformed(
Vector2.new(100, 100), -- Position
Vector2.new(2, 2), -- Scale
45, -- Rotation (degrees)
srcImage, -- Source image
{
CombineType = Enum.ImageCombineType.AlphaBlend, -- Optional, default is AlphaBlend
SamplingMode = Enum.ResamplerMode.Default, -- Optional, default is Default
PivotPoint = srcImage.Size / 2 -- Optional, default is center of the source image
}
)
EditableImage:DrawImageTransformed() - Crop

local AssetService = game:GetService("AssetService")
-- Source image
local srcImage = AssetService:CreateEditableImageAsync(Content.fromUri(assetUri))
-- Crop area defined by offset and size
local cropOffset = Vector2.new(50, 50)
local cropSize = Vector2.new(100, 100)
-- Destination image with size of the crop area
local dstImage = AssetService:CreateEditableImage({ Size = cropSize })
-- Position (top-left corner)
local position = Vector2.new(0, 0)
-- Scale factors (no scaling)
local scale = Vector2.new(1, 1)
-- Rotation angle (no rotation)
local rotation = 0
-- Draw the source image onto the destination image with adjusted pivot to crop the image
dstImage:DrawImageTransformed(
position,
scale,
rotation,
srcImage,
{
CombineType = Enum.ImageCombineType.Overwrite,
PivotPoint = cropOffset -- Set pivot point to cropOffset to start drawing from there
}
)

DrawLine

void

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

พารามิเตอร์

Start point of the line.

End point of the line.

color: Color3

Color of the line.

transparency: number

Transparency of the line.

How the pixels of the source image are blended with the pixels of the added image.


ส่งค่ากลับ

void

DrawRectangle

void

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

พารามิเตอร์

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.

How the pixels of the source image are blended with the pixels of the added image.


ส่งค่ากลับ

void

ReadPixelsBuffer

เขียนพร้อมๆ กัน

A version of ReadPixels() that returns a buffer instead of a table. Each number in the buffer is a single byte, while each number in the table is 4 bytes, making ReadPixelsBuffer() more memory-efficient than ReadPixels().

Note that this method uses alpha instead of transparency, unlike the EditableImage drawing methods.

พารามิเตอร์

position: Vector2

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

size: Vector2

Size of the rectangular region of pixels to read.


ส่งค่ากลับ

Buffer where each pixel is represented by four bytes (red, green, blue and alpha respectively). The length of the buffer can be calculated as Size.X * Size.Y * 4 bytes.

ตัวอย่างโค้ด

EditableImage:ReadPixelsBuffer()

local AssetService = game:GetService("AssetService")
local options = { Size = Vector2.new(32,32) }
local editableImage = AssetService:CreateEditableImage(options)
local pixelsBuffer = editableImage:ReadPixelsBuffer(Vector2.zero, Vector2.new(2, 1))
local color1 = Color3.fromRGB(buffer.readu8(pixelsBuffer, 0), buffer.readu8(pixelsBuffer, 1), buffer.readu8(pixelsBuffer, 2))
local transparency1 = 1 - buffer.readu8(pixelsBuffer, 3)
local color2 = Color3.fromRGB(buffer.readu8(pixelsBuffer, 4), buffer.readu8(pixelsBuffer, 5), buffer.readu8(pixelsBuffer, 6))
local transparency2 = 1 - buffer.readu8(pixelsBuffer, 7)
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

WritePixelsBuffer

void

A version of WritePixels() that takes a buffer instead of a table. Each number in the buffer is a single byte, while each number in the table is 4 bytes, making WritePixelsBuffer() more memory-efficient than WritePixels().

Note that this method uses alpha instead of transparency, unlike the EditableImage drawing methods.

พารามิเตอร์

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.

buffer: buffer

A buffer where each pixel is represented by four bytes (red, green, blue, and alpha respectively). The length of the buffer should be Size.X * Size.Y * 4 bytes.


ส่งค่ากลับ

void

ตัวอย่างโค้ด

EditableImage:WritePixelsBuffer()

local AssetService = game:GetService("AssetService")
local options = { Size = Vector2.new(32,32) }
local editableImage = AssetService:CreateEditableImage(options)
local pixelsBuffer = editableImage:ReadPixelsBuffer(Vector2.zero, editableImage.Size)
for i = 1, editableImage.Size.X * editableImage.Size.Y do
local pixelIndex = (i - 1) * 4
buffer.writeu8(pixelsBuffer, pixelIndex, 255 - buffer.readu8(pixelsBuffer, pixelIndex))
buffer.writeu8(pixelsBuffer, pixelIndex + 1, 255 - buffer.readu8(pixelsBuffer, pixelIndex + 1))
buffer.writeu8(pixelsBuffer, pixelIndex + 2, 255 - buffer.readu8(pixelsBuffer, pixelIndex + 2))
end
editableImage:WritePixelsBuffer(Vector2.zero, editableImage.Size, pixelsBuffer)

อีเวนต์