当前位置:网站首页>Unity picture loading and saving
Unity picture loading and saving
2022-06-23 07:35:00 【Niu Shenzi】
load :
1. asynchronous :( In fact, it is loaded in the main thread )
Use UnityWebRequest( perhaps WWW) Load pictures , You can load local ( Slow speed ,2048*1024 Size of the picture loading time 780ms, No card interface ) And online pictures .
UnityWebRequest request = UnityWebRequestTexture.GetTexture(Application.streamingAssetsPath + "/Test3.jpg");
yield return request.SendWebRequest();
if (request.downloadHandler.isDone)
{
var tex = DownloadHandlerTexture.GetContent(request);
}
2. Sync :
Use File To read ( Fast ,2048*1024 Size of the picture loading time 22ms, Card main thread interface , Short time for small pictures , Imperceptible )
var bytess = File.ReadAllBytes(Application.streamingAssetsPath + "/Test3.jpg");
var temp = new Texture2D(1, 1);
temp.LoadImage(bytess);
preservation :
1. Sync :
// This is a time-consuming step , The picture is big , Card master thread
var bytes3 = tex.EncodeToJPG();
// The following save can also be done asynchronously , But the storage time is very short , It can also be done without ,2048*1024 The storage time is about 1ms,
// Large pictures can be saved asynchronously
File.WriteAllBytes(Application.streamingAssetsPath + "/Test3.jpg", bytes3);
2. asynchronous :
var pixels = tex.GetPixels32(0);
GraphicsFormat format = tex.graphicsFormat;
uint width = (uint)tex.width;
uint height = (uint)tex.height;
Task.Run(() =>
{
var bytes3 = ImageConversion.EncodeArrayToJPG(pixels, format, width, height);
File.WriteAllBytes(Application.streamingAssetsPath + "/Test3.jpg", bytes3);
});
边栏推荐
- Pagoda forgot password
- 100 GIS practical application cases (79) - key points of making multi plan integrated base map
- g++编译命令使用
- 如何优雅的快速下载谷歌云盘的大文件 (二)
- MySQL(二) — MySQL数据类型
- Akamai-1.75版本-_abck参数生成-js逆向分析
- Download the OSS file and modify the file name
- How MySQL converts a date to a number
- Wechat multiplayer chat and Roulette Games (websocket Implementation)
- Nacos适配oracle11g-修改Nacos源码
猜你喜欢

NTU-RGBD数据集下载及数据格式解析

UNET code implementation

Yan's DP analysis

都是硬盘分区 C盘和D盘到底有什么区别?

Akamai-1.75版本-_abck参数生成-js逆向分析

传智教育 | 多人协作开发出现代码冲突,如何合并代码?
![[interface automation] software testing the core skills of salary increase to increase salary by 200%](/img/22/be8c5c922307225c34f6205f189c33.png)
[interface automation] software testing the core skills of salary increase to increase salary by 200%

In depth learning series 46: face image super score gfp-gan

Cirium has gradually become the standard for airlines' carbon dioxide emission reporting

Pagoda forgot password
随机推荐
Spock constraint - call frequency / target / method parameters
CIRIUM(睿思誉)逐渐成为航空公司二氧化碳排放报告的标准
The original cloud landed in deep water, and the cloud product family of Boyun container released four values
Learning and using quartz scheduling framework
Flannel 工作原理
Deep learning series 47: Super sub model real esrgan
NTU-RGBD数据集下载及数据格式解析
RFID data security experiment: C # visual realization of parity check, CRC redundancy check and Hamming code check
MySQL (11) - sorting out MySQL interview questions
ldconfig 命令
Redis设置密码
How to quickly and gracefully download large files from Google cloud disk (II)
左乘右乘矩阵问题
细说Idea那些骚操作
[deep learning] [original] how to detect targets and draw map and other parameter maps without yolov5 weights or models
codeforce 158B Taxi
How to verify date format in PHP (regular)
Tp6 installation expansion
[AI practice] xgbgressor model accelerates training and uses GPU to train xgbgressor in seconds
The List