Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将多字节数组图像数据合并到一字节数组数据集中,并将所有字节写入单个图像输出_C#_.net_Unity3d - Fatal编程技术网

C# 将多字节数组图像数据合并到一字节数组数据集中,并将所有字节写入单个图像输出

C# 将多字节数组图像数据合并到一字节数组数据集中,并将所有字节写入单个图像输出,c#,.net,unity3d,C#,.net,Unity3d,注意使用.net3.5框架。不,我不能使用System.Windows.Media中的任何类 概述 我发现有必要在我的屏幕上截取4张内容截图 内容分布在比我的屏幕区域更大的区域,该区域宽1618px,高696px 我自动化了4个区域的截图过程,然后用.png数据将从屏幕读取的像素编码为字节数组 然后,我使用System.IO.File.writealBytes将实际的png图像输出到路径中的文件夹中 问题 我确实在一个文件夹中输出了我所有的png图像,我可以成功地查看所有4幅图像。然而,我需要的

注意使用.net3.5框架。不,我不能使用System.Windows.Media中的任何类

概述

我发现有必要在我的屏幕上截取4张内容截图

内容分布在比我的屏幕区域更大的区域,该区域宽1618px,高696px

我自动化了4个区域的截图过程,然后用.png数据将从屏幕读取的像素编码为字节数组

然后,我使用
System.IO.File.writealBytes
将实际的png图像输出到路径中的文件夹中

问题

我确实在一个文件夹中输出了我所有的png图像,我可以成功地查看所有4幅图像。然而,我需要的图像是一个大的图像

i、 如图所示,显示3236 x 1392px的图像

在图像中,您刚刚看到四个1618pxBY和696px的正方形,标记为1到4。这代表了截图和拍摄顺序

这与我希望将图像合并并输出为单个3236x1392px图像的顺序完全相同

在这个班上。假设图像1、2、3和4的字节数据已经分配给各自的字节数组

class SimplePseudoExample
{
 private byte[] bytes1;
 private byte[] bytes2;
 private byte[] bytes3;
 private byte[] bytes4;

private byte FinalByes[];

void CreateTheSingleLargeImage()
{
 System.IO.File.WriteAllBytes("Path"+".png",FinalByes);
}

}

如何获得单个大图像输出?

一种方法是将它们转换为纹理,然后使用
getPixels
setPixels
进行合并

 tex1 = new Texture2D(2, 2);
 ImageConversion.LoadImage(tex1, bytes1);
 tex2 = new Texture2D(2, 2);
 ImageConversion.LoadImage(tex2, bytes2);
 tex3 = new Texture2D(2, 2);
 ImageConversion.LoadImage(tex3, bytes3);
 tex4 = new Texture2D(2, 2);
 ImageConversion.LoadImage(tex4, bytes4);


 outTex = new Texture2D(tex1.width * 2, tex1.height * 2);

 // we could use tex1.width,tex1.height for everything but this is easier to read

 // setPixels bottom-left is 0,0
 // bottom-left
 outTex.setPixels(0,0,
                  tex3.width,tex3.height,
                  tex3.getPixels());
 // bottom-right
 outTex.setPixels(tex3.width,0,
                  tex4.width,tex4.height,
                  tex4.getPixels());
 // top-left
 outTex.setPixels(0,tex3.height,
                  tex1.width,tex1.height,
                  tex1.getPixels());
 // top-right
 outTex.setPixels(tex3.width, tex3.height,
                  tex2.width,tex2.height,
                  tex2.getPixels());

 byte[] outBytes = outTex.EncodeToPNG();

这看起来不错。我一打开过热的电脑就去测试。