试图了解这个图像功能 [英] Trying to Understand this Image function

查看:134
本文介绍了试图了解这个图像功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void ReadImage()
    {
        int i, j;
        GreyImage = new int[Width, Height];  //[Row,Column]
        Bitmap image = Obj;
        BitmapData bitmapData1 = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                                 ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
        unsafe
        {
            byte* imagePointer1 = (byte*)bitmapData1.Scan0;

            for (i = 0; i < bitmapData1.Height; i++)
            {
                for (j = 0; j < bitmapData1.Width; j++)
                {
                    GreyImage[j, i] = (int)((imagePointer1[0] + imagePointer1[1] + imagePointer1[2]) / 3.0);
                    //4 bytes per pixel
                    imagePointer1 += 4;
                }//end for j
                //4 bytes per pixel
                imagePointer1 += bitmapData1.Stride - (bitmapData1.Width * 4);
            }//end for i
        }//end unsafe
        image.UnlockBits(bitmapData1);
        return;
    }

GreyImage [J,I =(INT)((imagePointer1 [0] ..... 似乎读入字节* 像一个数组,显然我不能code的不安全位分配给以后处理一个数组,所以我想也许只是分配这些4个字节的数组。

the line GreyImage[j,i] = (int)((imagePointer1[0] ..... seems to be reading into the byte* like an array, obviously I can't assign an unsafe bit of code to an array for later processing, so i thought maybe just assign those 4 bytes to the array.

你如何分配这些4个字节的阵列?

How do you assign those 4 bytes to the array?

我想这样做:

var imageData = new byte[Width, Height][];
imageData[x,y] = pixelSet //basically byte[];

任何想法

推荐答案

我认为你正在尝试做这样的事情。很显然,我没有测试此code,但它会得到你想要的方向。

I think you are trying to do something like this. Obviously, I haven't tested this code but it will get you in the direction you want.

byte[] save = new byte[4];
Array.Copy(*imagePointer1, save, 4);

byte[] save = new byte[4];
save[0] = bitmapData1.Scan0[0];
save[1] = *(imagePointer1 + 1);
save[2] = *(imagePointer1 + 2);
save[3] = *(imagePointer1 + 3);

一个指向数组的指针总是指向元素为零。您可以通过添加指针或递增指针访问其他元素。

A pointer to an array always points to element zero. You can access other elements by adding to the pointer or incrementing the pointer.

 (imagePointer1 + 5)  // pointer to 5th element
*(imagePointer1 + 5)  // value of 5th element
  imagePointer1 += 5; // imagePointer1 now starts at element 5

加号和减号通过移动组成数组的sizeof的数据类型的字节数的指针引用。如果它是一个int [],+和 - 将移动指针以4个字节为单位。

Plus and minus move the pointer reference by the number of bytes that make up the sizeof the array's data type. If it was an int[], + and - would move the pointer in increments of 4 bytes.

我希望这可以帮助你。

I hope this helps you out.

这篇关于试图了解这个图像功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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