如何将图像像素化转换为矩阵 [英] how to convert a image pixelated to matrix

查看:351
本文介绍了如何将图像像素化转换为矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

这个程序可以将图像转换为矩阵2d但是如果我想用像素化转换这个图像知道5x5或5度的像素那么我如何改变循环? br $>


  public   int  [] [] GetBitMapColorMatrix()
{

位图b1 = new 位图(imagess);
int hight = b1.Height;
int width = b1.Width;
int [] [] colorMatrix1 = new INT [宽度] [];
for int i = 0 ; i < width; i ++)
{
colorMatrix1 [i] = new int [hight];

for int j = 0 ; j < hight; j ++)
{
colorMatrix1 [i] [j] = new int ();
colorMatrix1 [i] [j] =(b1.GetPixel(i,j).B)/ 3 +(b1.GetPixel(i,j) .R)/ 3 +(b1.GetPixel(i,j).G)/ 3 ;
}
}
return colorMatrix1;

}

解决方案

永远不要使用 GetPixel / SetPixel 除非你只需要很少的;这太慢了。相反,使用 System.Drawing.Bitmap.LockBits

http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits.aspx [ ^ ]。



关于这两种方法的MSDN文章包含自解释代码示例,请参阅。



-SA

hello
this program can be converting a image to matrix 2d but if i want converting this image with pixelation knowing that a pixel of 5x5 or degree of 5 then How do I change in loops ?

public int[][] GetBitMapColorMatrix()
        {

            Bitmap b1 = new Bitmap(imagess);
            int hight = b1.Height;
            int width = b1.Width;
            int[][] colorMatrix1 = new int[width][];
            for (int i = 0; i < width; i++)
            {
                colorMatrix1[i] = new int[hight];

                for (int j = 0; j < hight; j++)
                {
                    colorMatrix1[i][j] = new int();
                    colorMatrix1[i][j] = (b1.GetPixel(i, j).B) / 3 + (b1.GetPixel(i, j).R) / 3 + (b1.GetPixel(i, j).G) / 3;
                }
            }
            return colorMatrix1;

        }

解决方案

Never use GetPixel/SetPixel unless you only need very few of them; this is prohibitively slow. Instead, use System.Drawing.Bitmap.LockBits:
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.lockbits.aspx[^].

The MSDN articles on these two methods contain self-explaining code samples, please see.

—SA


这篇关于如何将图像像素化转换为矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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