如何在 C# 中使用 32 位浮点图像?
我更喜欢使用 openExr 但是,tiff 或类似的也可以,基本上我只想从磁盘加载一个 32 位浮点(每像素/通道 32 位)图像并获取单个通道的像素值并将其放入数组,最好是尽可能简单的解决方案。
代码:C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
using System.IO;
namespace ImgToVxlForm
{
public partial class Form1 : Form
{
Bitmap myBitmap;
Byte[] byteArr;
public Form1()
{
InitializeComponent();
}
private void browseBtn_Click(object sender, EventArgs e)
{
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Title = "Open Image";
dlg.Filter = "png files (*.png)|*.png";
if (dlg.ShowDialog() == DialogResult.OK)
{
myBitmap = new Bitmap(dlg.FileName);
pictureBox1.Image = myBitmap;
}
}
}
private void runBtn_Click(object sender, EventArgs e)
{
byteArr = (ImageToArr(myBitmap));
for (int i = 0; i < byteArr.Length; i++)
{
// Debug.WriteLine(byteArr[i]);
}
lb_debug.Text = byteArr.Length.ToString();
}
public static byte[] ImageToArr(Bitmap inBitmap)
{
int w = inBitmap.Width;
int h = inBitmap.Height;
Byte[] tmpByteArr = new byte[w * h];
int count = 0;
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
Color pixelColor = inBitmap.GetPixel(x, y);
tmpByteArr[count] = pixelColor.R;
count++;
}
}
return tmpByteArr;
}
}
}