EditableImage
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
EditableImage は、画像のランタイム作成と操作を許可します。
空の EditableImage を作成するには、AssetService:CreateEditableImage() を使用します。既存の画像から EditableImage を作成するには、AssetService:CreateEditableImageAsync() を使用します。
EditableImage は、Content または ImageLabel.ImageContent など、画像を取得するすべての MeshPart.TextureContent プロパティで使用できます。これはコンテンツプロパティを Content.fromObject(editableImage) に設定して行われます。
EditableImage 座標システムは、画像の左上に相対する:
- 左上: (0, 0)
- 下右: (Size.X - 1, Size.Y - 1)
When you use AssetService:PromptCreateAssetAsync() to publish an object that has a Content プロパティ which references an EditableImage , the editable image is published as an image and the property is set to a new asset ID.
制限を更新する
表示側では、フレームごとに単一の EditableImage のみが更新できます。たとえば、現在表示されている 3 個の EditableImage オブジェクトを更新する場合、すべてのオブジェクトを更新するには 3 フレームがかかります。
公開エクスペリエンスで編集可能な画像を有効にする
セキュリティ目的で、EditableImage を使用すると、公開エクスペリエンスにデフォル本人確認済みで失敗します。EditableImage の使用を有効にするには、13歳以上の年齢を確認し、IDを確認する必要があります。認証が完了した後、 Studio を開きます。Select ファイル > ゲーム設定 > セキュリティ and enable the メッシュと画像 API を許可する toggle.トグルを有効にする前に、利用条件を確認することを忘れないでください。
許可
悪用を防ぐために、AssetService:CreateEditableImageAsync() は画像アセットのロードと編集のみを許可します:
- エクスペリエンスの作成者が所有しているもの (エクスペリエンスが個人によって所有されている場合)。
- グループが所有しているもの (エクスペリエンスがグループに所有されている場合)。
- ログイン済みのスタジオユーザーが所有するもの (場所ファイルが Roblox に保存されたり公開されたりしていない場合)
APIs は、上記の基準を満たさないアセットをロードするために使用された場合、エラーをスローします。
概要
方法
- DrawCircle(center : Vector2,radius : number,color : Color3,transparency : number,combineType : Enum.ImageCombineType):()
指定されたポイントで円を描画します。
指定された位置に別の EditableImage をこの EditableImage に描画します。
別の EditableImage を EditableMesh にプロジェクトし、結果をこの EditableImage に保存します。
- DrawImageTransformed(position : Vector2,scale : Vector2,rotation : number,image : EditableImage,options : Dictionary?):()
スケーリングや回転などの変換を含む画像をこの EditableImage に描画し、指定された位置に配置します。
提供された 2つのポイントの間に線を描きます。
- DrawRectangle(position : Vector2,size : Vector2,color : Color3,transparency : number,combineType : Enum.ImageCombineType):()
指定された上左位置で、指定されたサイズの長方形を描画します。
ピクセルの長方形の領域をバッファに読み込みます。
ピクセルの長方形の領域を画像に書き込みます。
プロパティ
Size
ピクセルでの EditableImage のサイズ。最大サイズは 1024×1024です。EditableImage はサイズを変更できません;このプロパティは読み取り専用です。画像を再サイズ化またはトリミングするには、新しい EditableImage を作成し、コンテンツを移行するために DrawImageTransformed() を使用し、次に Destroy() を呼び出します。
方法
Destroy
画像の内容を破壊し、使用済みメモリをすぐに回収します。
戻り値
DrawCircle
指定されたポイントの EditableImage に円を描画します。円が半透明の場合、ソースオーバーブレンドを使用して背後のピクセルとブレンドされます。
パラメータ
円の中心、EditableImage の上左隅に対して。キャンバスの境界外の位置は許可されています。
ピクセルで円の半径。
円の色。
0が完全に不透明で、1が完全に透明な円の透明度
ソース画像のピクセルと追加画像のピクセルがどのようにブレンドされるか。
戻り値
DrawImage
指定された位置に別の EditableImage をこの EditableImage に描画します。キャンバスの境界外の位置は、新しい画像の一部だけが描かれるように許可されています。
パラメータ
追加された画像の左上隅が描かれる位置。
この EditableImage に描画する EditableImage 。
ソース画像のピクセルと追加画像のピクセルがどのようにブレンドされるべきか。
戻り値
DrawImageProjected
指定されたプロジェクションとブラシの設定を使用して、別の EditableImage を EditableMesh にプロジェクトし、結果をこの EditableImage に保存します。
パラメータ
投影するために使用される EditableMesh。
次のキー-バリューペアを含むブラシ構成辞書:
- AlphaBlendType ( Enum.ImageAlphaType ) これは、このプロジェクションがアルファ値をどのようにブレンドするかを決定します。
- ColorBlendType ( Enum.ImageCombineType ) これは、このプロジェクションが色値をブレンドする方法を決定します。
- Decal ( EditableImage ) は、プロジェクションに使用される画像として。
- FadeAngle (number) は、プロジェクションエッジが落オフる角度を度数として (number) です。
- BlendIntensity (number) は、0 と 1 の間の値として、プロジェクションのどの程度が結果画像にブレンドされるかを制御します。
戻り値
DrawImageTransformed
このメソッドでは、スケーリングや回転などの変換を適用して、この EditableImage に EditableImage を描画できます。位置パラメータは、変換後にソース画像のピボットポイントがこの画像に置かれる場所を指定します。キャンバスの境界外の位置は、新しい画像の一部だけが描かれるように許可されています。
パラメータ
ソース画像のピボットポイントがこの画像に配置される位置のピクセル。
XとY軸に沿ってソース画像のスケーリング因子。
ソース画像のピボットポイントの周りに適用される回転角度 (度)。
この画像に描画されるソース EditableImage 。
追加の構成のためのオプション辞書:
- CombineType : ソース画像のピクセルと目的地のピクセルがどのようにブレンドするかを指定します。デフォルトは Enum.ImageCombineType.AlphaBlend です。
- SamplingMode : サンプリング方法を指定 (例えば、Default は二次元またはPixelated は最も近い隣接者)。デフォルトは Enum.ResamplerMode.Default です。
- PivotPoint : ソース画像内のピボットポイントをスケーリングと回転のために指定します。デフォルトは、ソース画像の中心 (つまり Image.Size / 2 ) です。
戻り値
コードサンプル
The following code draws a rotated and scaled image onto another.
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
}
)
The following code shows how cropping an image can be done using the EditableImage:DrawImageTransformed() method.
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
提供された 2つのポイントの間の 1ピクセル厚の反アリアス線を描画します。draws an anti-aliased line on the EditableImage one pixel thick between the two provided points.
パラメータ
行の開始ポイント。
行の終端点。
ラインの色。
ラインの透明性。
ソース画像のピクセルと追加画像のピクセルがどのようにブレンドされるか。
戻り値
DrawRectangle
指定された上左位置の EditableImage に指定されたサイズの長方形を描画します。
パラメータ
正方形の左上の位置。他の描画方法とは異なり、これは EditableImage のキャンバス境界外には出せません。
描画する長方形のサイズ、ピクセルです。
長方形の色。
長方形の透明度。
ソース画像のピクセルと追加画像のピクセルがどのようにブレンドされるか。
戻り値
ReadPixelsBuffer
EditableImage からピクセルの長方形の領域を読み込み、バッファとして返すバッファ内の各番号は、4バイトのシーケンス(赤、緑、青、そしてアルファ)に保存されたピクセルで、単一のバイトです。
このメソッドは、透明度の代わりにアルファを使用し、EditableImage 描画メソッドとは異なります。
パラメータ
戻り値
それぞれのピクセルが 4バイトで表されるバッファ (それぞれ赤、緑、青、そしてアルファ)バッファの長さは Size.X * Size.Y * 4 バイトとして計算できます。
コードサンプル
The following code reads two pixels from a EditableImage and creates a part with the average color between them.
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 = (255 - buffer.readu8(pixelsBuffer, 3)) / 255
local color2 =
Color3.fromRGB(buffer.readu8(pixelsBuffer, 4), buffer.readu8(pixelsBuffer, 5), buffer.readu8(pixelsBuffer, 6))
local transparency2 = (255 - buffer.readu8(pixelsBuffer, 7)) / 255
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
バッファから長方形のピクセル領域を EditableImage に書き込みます。バッファ内の各番号は、4バイトのシーケンス(赤、緑、青、そしてアルファ)に保存されたピクセルで、単一のバイトです。
このメソッドは、透明度の代わりにアルファを使用し、EditableImage 描画メソッドとは異なります。
パラメータ
長方形の領域の左上隅にピクセルを描画する。
書き込むピクセルの長方形領域のサイズ。
それぞれのピクセルが 4バイトで表されるバッファ (それぞれ赤、緑、青、そしてアルファ)バッファの長さは Size.X * Size.Y * 4 バイトであるべきです。
戻り値
コードサンプル
The following code reads the pixels of a EditableImage and writes back the inverted color values of those pixels.
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))
-- Set alpha to 255 to make all pixels fully opaque.
buffer.writeu8(pixelsBuffer, pixelIndex + 3, 255)
end
editableImage:WritePixelsBuffer(Vector2.zero, editableImage.Size, pixelsBuffer)