旅行通过BMP像素像素、旅行、BMP

由网友(孤独的心态)分享简介:您好我有一个 BMP 加载到旅游虽然像素作为上述要求的一个 BMP 对象和IM图像从(1,1)像素(100,100)像素。使用与getPixel()方法。我用了一个循环,但没有成功。 如果使用多维数组的概念应该是什么变量值IM?解决方案 当你想要做的图像处理在巨大的图像getPixel()方法需要很长时间但我认为...

您好我有一个 BMP 加载到旅游虽然像素作为上述要求的一个 BMP 对象和IM图像从(1,1)像素(100,100)像素。使用与getPixel()方法。我用了一个循环,但没有成功。

如果使用多维数组的概念应该是什么变量值IM?

解决方案   

当你想要做的图像处理   在巨大的图像getPixel()方法需要很长时间   但我认为我的算法需要更少   时间比其他的答案,比如   您可以测试在800 * 600这个code   像素的图像。

  BMP位图=新位图(SomeImage);

//锁定位的位。
矩形RECT =新的Rectangle(0,0,bmp.Width,bmp.Height);
的BitmapData bmpData = bmp.LockBits(矩形,ImageLockMode.ReadWrite,PixelFormat.Format24bppRgb);

//获取第一行的地址。
IntPtr的PTR = bmpData.Scan0;

//声明一个数组来保存位图的字节。
INT字节= bmpData.Stride * bmp.Height;
byte []的rgbValues​​ =新的字节[字节];
byte []的R =新的字节[字节/ 3]。
byte []的G =新的字节[字节/ 3]。
byte []的B =新的字节[字节/ 3]。

//复制的RGB值到数组。
Marshal.Copy(PTR,rgbValues​​,0,字节);

诠释计数= 0;
INT跨距= bmpData.Stride;

对于(INT列= 0;柱< bmpData.Height;列++)
{
    对于(INT行= 0;行< bmpData.Width;排++)
    {
        B〔数=(字节)(rgbValues​​ [(列*步幅)+(行* 3)]);
        政[统计] =(字节)(rgbValues​​ [(列*步幅)+(行* 3)+ 1]);
        ř[计数++] =(字节)(rgbValues​​ [(柱*步幅)+(行* 3)+2]);
    }
}
 
高像素 多玩法 出游必备拍照4G手机盘点

Hi i have a bmp loaded to a BMP object and im required to travel though the pixels as the above image from (1,1) pixel to (100,100) px . using getpixel() method. I was using was ONE loop but it was not successful .

If im using the concept of multidimensional array what should be variable values ?

解决方案

When you want to doing image processing on huge images GetPixel() method takes long time but I think my algorithm takes less time than other answers , for example you can test this code on 800 * 600 pixels image.

Bitmap bmp = new Bitmap("SomeImage");

// Lock the bitmap's bits.  
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

// Get the address of the first line.
IntPtr ptr = bmpData.Scan0;

// Declare an array to hold the bytes of the bitmap.
int bytes = bmpData.Stride * bmp.Height;
byte[] rgbValues = new byte[bytes];
byte[] r = new byte[bytes / 3];
byte[] g = new byte[bytes / 3];
byte[] b = new byte[bytes / 3];

// Copy the RGB values into the array.
Marshal.Copy(ptr, rgbValues, 0, bytes);

int count = 0;
int stride = bmpData.Stride;

for (int column = 0; column < bmpData.Height; column++)
{
    for (int row = 0; row < bmpData.Width; row++)
    {
        b[count] = (byte)(rgbValues[(column * stride) + (row * 3)]);
        g[count] = (byte)(rgbValues[(column * stride) + (row * 3) + 1]);
        r[count++] = (byte)(rgbValues[(column * stride) + (row * 3) + 2]);
    }
}

阅读全文

相关推荐

最新文章