ImageLabel

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

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

An ImageLabel renders a rectangle, like a Frame does, with an image asset. The display of the image can be manipulated through the ImageColor3 and ImageTransparency properties. To display only the image and hide the rectangle, set GuiObject.BackgroundTransparency to 1.

Advanced ImageLabel usage includes:

สรุป

คุณสมบัติ

  • Image:ContentId
    อ่านพร้อมๆ กัน

    The image content displayed by the UI element. Reads and writes to ImageContent.

  • อ่านพร้อมๆ กัน

    Determines how a rendered image will be colorized.

  • ซ่อนอยู่
    อ่านพร้อมๆ กัน

    The image content displayed by the UI element. Supports asset URIs and EditableImage objects.

  • อ่านพร้อมๆ กัน

    The offset in pixels of the sub-area of an image to be displayed.

  • อ่านพร้อมๆ กัน

    Determines the size in pixels of the sub-area of an image to be displayed.

  • อ่านพร้อมๆ กัน

    Determines the transparency of the rendered image.

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

    Indicates whether the image has finished loading from Roblox.

  • อ่านพร้อมๆ กัน

    Selects the image resampling mode for the label.

  • อ่านพร้อมๆ กัน

    Determines how an image will scale if displayed in a UI element whose size differs from the source image.

  • อ่านพร้อมๆ กัน

    Sets the slice boundaries of a 9-sliced image.

  • อ่านพร้อมๆ กัน

    Scales the 9-slice edges by the specified ratio.

  • อ่านพร้อมๆ กัน

    Sets the tiling size of the ImageLabel.

คุณสมบัติรับทอดมาจากGuiObjectคุณสมบัติรับทอดมาจากGuiBase2d

วิธีการ

วิธีการรับทอดมาจากGuiObject

อีเวนต์

อีเวนต์รับทอดมาจากGuiObjectอีเวนต์รับทอดมาจากGuiBase2d

คุณสมบัติ

Image

ContentId
อ่านพร้อมๆ กัน

This property is a content-type property that should hold the asset ID of a decal or image uploaded to Roblox. It functions identically to Decal.Texture with regards to loading the image from Roblox. The rendered image can be modified using ImageColor3 and ImageTransparency.

ImageColor3

อ่านพร้อมๆ กัน

The ImageColor3 property determines how an image is colorized. When set to white, no colorization occurs. This property is very useful for reusing image assets; if the source image is completely white with transparency, you can set the entire color of the image at once with this property.

ImageContent

ซ่อนอยู่
อ่านพร้อมๆ กัน

This property should hold an asset URI or a reference to an EditableImage object.

The asset URI can reference a decal or image uploaded to Roblox. It functions identically to Decal.Texture with regards to loading the image.

The rendered image will be colorized using ImageButton.ImageColor3. It is possible to make the image render as tiled, scaled to fit, or 9-sliced, by adjusting the ImageButton.ScaleType property.

ImageRectOffset

อ่านพร้อมๆ กัน

Allows the partial display of an image in conjunction with ImageRectSize. This property determines the pixel offset (from the top-left) of the image area to be displayed.

ImageRectSize

อ่านพร้อมๆ กัน

Allows the partial display of an image in conjunction with ImageRectOffset. This property determines the pixel size of the image area to be displayed. If either dimension is set to 0, the entire image is displayed instead.

ImageTransparency

อ่านพร้อมๆ กัน

ImageTransparency determines the alpha of a UI element's rendered image. A value of 0 is completely opaque and a value of 1 is completely transparent (invisible).

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

Oscillate ImageTransparency

local RunService = game:GetService("RunService")
local imageLabel = script.Parent
local function onRenderStep()
-- Oscillate ImageTransparency from 0 to 1 using a sine wave
imageLabel.ImageTransparency = math.sin(workspace.DistributedGameTime * math.pi) * 0.5 + 0.5
end
RunService.RenderStepped:Connect(onRenderStep)

IsLoaded

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

The IsLoaded property indicates if the ImageLabel.Image property has finished loading from Roblox. Images declined by moderation will never load.

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

Image Load Time

local imageLabel = script.Parent
local startTime = workspace.DistributedGameTime
-- Wait for the image to load
while not imageLabel.IsLoaded do
task.wait()
end
-- Measure and display how long it took to load
local deltaTime = workspace.DistributedGameTime - startTime
print(("Image loaded in %.3f seconds"):format(deltaTime))

ResampleMode

อ่านพร้อมๆ กัน

Determines how the image looks when it is scaled. By default, the image smooths out texturing when displayed on the screen larger or smaller than its size in texture memory. When set to Enum.ResamplerMode.Pixelated, the image preserves the sharp edges of pixels.

อ่านพร้อมๆ กัน

The ScaleType property determines in what way an ImageLabel.Image is rendered when the UI element's absolute size differs from the source image's size.

By default, this property is Enum.ScaleType.Stretch which will simply stretch/compact the image dimensions so it fits the UI element's space exactly. Since transparent pixels are set to black when uploading to Roblox, transparent images should apply alpha blending to avoid a blackish outline around scaled images.

For Enum.ScaleType.Slice, the SliceCenter property will be revealed in the Properties window. This is for nine-slice UI: when scaling up, the corners will remain the source image size. The edges of the image will stretch to the width/height of the image. Finally, the center of the image will stretch to fill the center area of the image.

Finally, for Enum.ScaleType.Tile, the TileSize property will be revealed in the Properties window. This is for tiled images, where the size of each image tile is determined by the TileSize property.

SliceCenter

อ่านพร้อมๆ กัน

The SliceCenter property sets the slice boundaries of a 9-sliced image when ScaleType is set to Enum.ScaleType.Slice. Please note that this property is only visible in the Properties window under this condition.

To learn more about 9-slice images, see UI 9 Slice Design.

SliceScale

อ่านพร้อมๆ กัน

Scales the 9-slice edges by the specified ratio. This means that the edges around the 9-slice will grow as if you'd uploaded a new version of the texture upscaled. Defaults to 1.0.

See also ScaleType, SliceCenter, and SliceScale.

TileSize

อ่านพร้อมๆ กัน

TileSize sets the tiling size of the ImageLabel with a default of UDim2.new(1, 0, 1, 0). Tiling starts at the top-left corner of the image. This property is only active if the ScaleType for the ImageLabel is set to Enum.ScaleType.Tile.

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

Image ScaleType Demo

local imageLabel = script.Parent
-- Set the source image to be a 64x64 padlock
imageLabel.Image = "rbxassetid://284402752"
imageLabel.BackgroundTransparency = 0
imageLabel.BackgroundColor3 = Color3.new(1, 1, 1) -- White
imageLabel.ImageColor3 = Color3.new(0, 0, 0) -- Black
local function resizeInACircle()
for theta = 0, 2, 0.02 do
imageLabel.Size = UDim2.new(
0,
100 + math.cos(theta * 2 * math.pi) * 50,
0,
100 + math.sin(theta * 2 * math.pi) * 50
)
task.wait()
end
end
while true do
-- Stretch simply stretches the source image to fit
-- the UI element's space
imageLabel.ScaleType = Enum.ScaleType.Stretch
resizeInACircle()
-- Tile will render the source image multiple times
-- enough to fill the UI element's space
imageLabel.ScaleType = Enum.ScaleType.Tile
imageLabel.TileSize = UDim2.new(0, 64, 0, 64)
resizeInACircle()
-- Slice will turn the image into a nine-slice UI.
imageLabel.ScaleType = Enum.ScaleType.Slice
imageLabel.SliceCenter = Rect.new(30, 30, 34, 34)
resizeInACircle()
end

วิธีการ

อีเวนต์