وصول بيانات البكسل في TextureData
Contents
[
Hide
]
هذا مدعوم بالإصدار 23.4 أو أكبر.
كتابة بيانات البكسل
استخدم الفئة التالية لتحديد مشفرات النسيج وفك تشفيره:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tex = new TextureData(128, 128, PixelFormat.A8R8G8B8); | |
using (var mapping = tex.MapPixels(PixelMapMode.WriteOnly)) | |
{ | |
var pixels = mapping.Data; | |
var p = 0; | |
for(var y = 0; y < 128; y++) | |
{ | |
for (var x = 0; x < 128; x++) | |
{ | |
pixels[p + 0] = 255;//alpha | |
pixels[p + 1] = 255;//red | |
pixels[p + 2] = 0;//green | |
pixels[p + 3] = 0;//blue | |
p += 4;//next pixel | |
} | |
} | |
} | |
tex.Save("red.png");//save to png file(Need codec registered) |
تحويل تنسيق البكسل
مع TransformPixelFormat يمكنك بسهولة تغيير تنسيق البكسل للنسيج:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tex = TextureData.FromFile("test.png"); | |
tex.TransformPixelFormat(PixelFormat.G8);//now the texture data only contains green channel in pixel. |