旋转一维数组中存储的位图 [英] Rotate a bitmap stored in a 1D array

查看:87
本文介绍了旋转一维数组中存储的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第二个代码示例是正确的答案.我的问题不在位图旋转本身之外,因此第二个代码示例是标题中问题的答案.

The second code example is the right answer. My problem was outside the bitmap rotation itself so the second code example is the answer to the question in the title.

我正在尝试旋转存储在1D数组(_pixelData)中的位图.我似乎无法正常工作.有人可以指出我正确的方向还是提供示例解决方案.

I'm trying to rotate a bitmap stored in a 1D array (_pixelData). I just can't seem to get it working. Could someone point me to the right direction or give an example solution.

图像为320 x 240像素,并存储在一个1D数组中(前320个值代表位图中的第一行,下320个值代表下一行,依此类推).

The image is 320 x 240 pixels and stored in a 1D array (first 320 values represent the first line in the bitmap, the next 320 the next line and so on).

我不想将其写入writeablebitmap那里旋转它并将其bact转换为int数组.我想操作int数组.原因是源来自相机的ARGB数据,我想保持简单.

I don't want to write it to a writeablebitmap rotate it there and convert it bact to int array. I want to operate the int array. The reason for this is that the source comes from camera as ARGB data and I want to keep this simple.

这就是我所拥有的(不起作用.结果是垂直线不相交的图像破碎)

Here's what I've got (doesn't work. The result is a broken image where the vertical lines don't meet)

// Rotate the data for Portait Mode
            int height = 320;
            int width = 240;
            int[] _pixelDataRotated = new int[width* height];
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                    _pixelDataRotated[x * height + height - y - 1] = _pixelData[x + y * width];
            }

这就是我做的方法,它可以旋转. 这就是答案.

This is how I've done it and it does to rotation. This is the answer.

    for (int x = 0; x < width; x++)
      for (int y = 0; y < height; y++)
         _pixelDataRotated[y + x * height] = _pixelData[x + y * width];

推荐答案

这就是答案.是以我最初的问题为例,但我认为它已被打破,但事实证明实际的问题出在位图图像尺寸上,而不是90度旋转本身的算法.

This was the answer. It was in my original question as an example but I thought it was broken but it turned out that the actual problem was in the bitmap image dimensions and not the algorithm for the 90 degree rotation itself.

// _pixelData is the source array _pixelDataRotated the target array
for (int x = 0; x < width; x++)
  for (int y = 0; y < height; y++)
     _pixelDataRotated[y + x * height] = _pixelData[x + y * width];

这篇关于旋转一维数组中存储的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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