data | Raw data array to initialize texture pixels with. |
size | データのサイズ(単位はバイト)。 |
Raw 形式データを読み取ってテクスチャのピクセルを格納します。
この関数はテクスチャピクセルメモリに Raw データを格納します。これは、圧縮テクスチャ形式データをテクスチャに読み込むには最も有用です。
Passed data should be of required size to fill the whole texture according to its width, height, data format and mipmapCount; otherwise a UnityException is thrown. Mipmaps are laid out in memory starting from largest, with smaller mip level data immediately following. For example, a 16x8 texture of RGBA32 format with no mipmaps can be filled with a 512-byte array (16x8x4).
For runtime texture generation, it is also possible to directly write into texture data via GetRawTextureData that returns a Unity.Collections.NativeArray
. This can be faster since it avoids a memory copy that LoadRawTextureData would do.
実際にグラフィックスカードによって変更されたピクセルをアップロードして Apply を呼び出します。
See Also: SetPixels, SetPixels32, SetPixelData, Apply, GetRawTextureData, ImageConversion.LoadImage.
using UnityEngine;
public class ExampleScript : MonoBehaviour { public void Start() { // Create a 16x16 texture with PVRTC RGBA4 format // and fill it with raw PVRTC bytes. Texture2D tex = new Texture2D(16, 16, TextureFormat.PVRTC_RGBA4, false); // Raw PVRTC4 data for a 16x16 texture. This format is four bits // per pixel, so data should be 16*16/2=128 bytes in size. // Texture that is encoded here is mostly green with some angular // blue and red lines. byte[] pvrtcBytes = new byte[] { 0x30, 0x32, 0x32, 0x32, 0xe7, 0x30, 0xaa, 0x7f, 0x32, 0x32, 0x32, 0x32, 0xf9, 0x40, 0xbc, 0x7f, 0x03, 0x03, 0x03, 0x03, 0xf6, 0x30, 0x02, 0x05, 0x03, 0x03, 0x03, 0x03, 0xf4, 0x30, 0x03, 0x06, 0x32, 0x32, 0x32, 0x32, 0xf7, 0x40, 0xaa, 0x7f, 0x32, 0xf2, 0x02, 0xa8, 0xe7, 0x30, 0xff, 0xff, 0x03, 0x03, 0x03, 0xff, 0xe6, 0x40, 0x00, 0x0f, 0x00, 0xff, 0x00, 0xaa, 0xe9, 0x40, 0x9f, 0xff, 0x5b, 0x03, 0x03, 0x03, 0xca, 0x6a, 0x0f, 0x30, 0x03, 0x03, 0x03, 0xff, 0xca, 0x68, 0x0f, 0x30, 0xaa, 0x94, 0x90, 0x40, 0xba, 0x5b, 0xaf, 0x68, 0x40, 0x00, 0x00, 0xff, 0xca, 0x58, 0x0f, 0x20, 0x00, 0x00, 0x00, 0xff, 0xe6, 0x40, 0x01, 0x2c, 0x00, 0xff, 0x00, 0xaa, 0xdb, 0x41, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xe8, 0x40, 0x01, 0x1c, 0x00, 0xff, 0x00, 0xaa, 0xbb, 0x40, 0xff, 0xff, }; // Load data into the texture and upload it to the GPU. tex.LoadRawTextureData(pvrtcBytes); tex.Apply(); // Assign texture to renderer's material. GetComponent<Renderer>().material.mainTexture = tex; } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.