Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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# 将UInt32数组转换为图像/位图 我有一个UIT32元素数组,其中每个元素代表图像上的RGB像素(对于记录,我从LabVIEW C++ DLL接收这个数组)。我正在尝试将此数组转换为System.Drawing.Bitmap,以便稍后将其保存为文件或显示在应用程序中_C#_.net - Fatal编程技术网

C# 将UInt32数组转换为图像/位图 我有一个UIT32元素数组,其中每个元素代表图像上的RGB像素(对于记录,我从LabVIEW C++ DLL接收这个数组)。我正在尝试将此数组转换为System.Drawing.Bitmap,以便稍后将其保存为文件或显示在应用程序中

C# 将UInt32数组转换为图像/位图 我有一个UIT32元素数组,其中每个元素代表图像上的RGB像素(对于记录,我从LabVIEW C++ DLL接收这个数组)。我正在尝试将此数组转换为System.Drawing.Bitmap,以便稍后将其保存为文件或显示在应用程序中,c#,.net,C#,.net,现在,我的代码遍历每个元素,将其转换为uint r、g和b,从中创建SystemDrawing.Color并在位图图像对象中设置像素。这是代码(我正在使用指针): 固定(uint*arrPtr=img.elt) { uint*pixelPtr=arrPtr; 位图图像=新位图(img.dimSizes[1],img.dimSizes[0]); 对于(int y=0;y16)和255; uint g=(arrPtr[img.dimSizes[1]*y+x]>>8)和255; uint b=arrP

现在,我的代码遍历每个元素,将其转换为uint r、g和b,从中创建SystemDrawing.Color并在位图图像对象中设置像素。这是代码(我正在使用指针):

固定(uint*arrPtr=img.elt)
{
uint*pixelPtr=arrPtr;
位图图像=新位图(img.dimSizes[1],img.dimSizes[0]);
对于(int y=0;y>16)和255;
uint g=(arrPtr[img.dimSizes[1]*y+x]>>8)和255;
uint b=arrPtr[img.尺寸[1]*y+x]&255;
颜色c=颜色。来自argb(255,(int)r,(int)g,(int)b);
设置像素(x,y,c);
}
}
image.Save(“Test.jpg”);
}
}
当然,这种方法效率太低,所以我的问题是: 是否有更快的方法将表示图像RGB像素的UInt32阵列转换为实际的System.Drawing.image对象?

使用覆盖:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Convert convert = new Convert();
            convert.integers = new uint[100];
            convert.bytes = new byte[4 * 100];
            convert.integers = Enumerable.Range(0, 100).Select(x => (uint)x).ToArray();

            foreach (byte b in convert.bytes)
            {
                Console.WriteLine(b);
            }
            Console.ReadLine();
       }
        [StructLayout(LayoutKind.Explicit)]
        public struct Convert
        {
            [FieldOffset(0)]
            public uint[] integers;
            [FieldOffset(0)]
            public byte[] bytes;
        }
    }
}

这回答了你的问题吗?通常用于.Btw、
image.Save(“Test.jpg”)
实际上使用
.jpg
扩展名保存
PNG
图像。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Convert convert = new Convert();
            convert.integers = new uint[100];
            convert.bytes = new byte[4 * 100];
            convert.integers = Enumerable.Range(0, 100).Select(x => (uint)x).ToArray();

            foreach (byte b in convert.bytes)
            {
                Console.WriteLine(b);
            }
            Console.ReadLine();
       }
        [StructLayout(LayoutKind.Explicit)]
        public struct Convert
        {
            [FieldOffset(0)]
            public uint[] integers;
            [FieldOffset(0)]
            public byte[] bytes;
        }
    }
}