如何将位图的1D字节数组转换为2D字节数组? [英] How can I convert a 1D byte array of a bitmap into a 2D byte array?

查看:86
本文介绍了如何将位图的1D字节数组转换为2D字节数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个测试程序并将PNG图像加载到其中,



https://dotnetfiddle.net/XHwp7o



像素格式= 32位颜色

位图分辨率,

宽度= 512像素

高度= 512像素

位图的步幅= 2048像素

偏移或填充=(步幅 - 宽度)=(2048 - 512)= 1336像素。

1D字节数组的大小= 1048576字节



如果我们将Bitmap转换为2D数组会有什么尺寸?



如何将Bitmap的1D字节数组转换为同一Bitmap的2D字节数组?



我有什么试过:



https://dotnetfiddle.net/XHwp7o

I have written a test program and loaded a PNG image into it,

https://dotnetfiddle.net/XHwp7o

Pixel format = 32 bit color
Resolution of the Bitmap,
Width = 512 pixels
Height = 512 pixels
Stride of the Bitmap = 2048 pixels
Offset or Padding = (Stride - Width) = (2048 - 512) = 1336 pixels.
Size of the 1D byte array = 1048576 bytes

What would be the dimensions if we convert the Bitmap to a 2D array?

How can I convert a 1D byte array of a Bitmap into a 2D byte array of the same Bitmap?

What I have tried:

https://dotnetfiddle.net/XHwp7o

推荐答案

首先,在您的位图属性报告中有一些注意事项:



1.步幅通常以字节为单位报告,而不是像素。

2.每个像素为4个字节(32位)。

3.这意味着您的偏移或填充将为0(2048字节 - 512 * 4字节)。



位图的每一行将是512 * 4 = 2018字节,并且将有512行。这意味着只需将1D字节数组的每个连续2048字节复制到2D数组的每一行。
Firstly, there are a few things to note in your report of the bitmap attributes:

1. Stride is usually reported in bytes, not pixels.
2. Each pixel is 4 bytes (32 bits).
3. This means that your offset or padding will be 0 (2048 bytes - 512*4 bytes).

Each row of your bitmap will be 512 * 4 = 2018 bytes, and there will be 512 rows. This means that it is simply a case of copying each sequential 2048 bytes of your 1D byte array into each row of the 2D array.


这篇关于如何将位图的1D字节数组转换为2D字节数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆