2011-10-22 20 views
0

对不起,我不知道如何设置一个主题,可以表达我需要什么帮助。一种列出字节数组像素值的方法

我有一个字节数组,位图中每个像素的值。它是从左到右的一维数组。它占用每行并将其添加到数组索引的末尾。

我想分割一个位图为225(= 15 * 15)件。每块砖具有例如尺寸34×34,并且阵列的长度为260×100(= 225×34×34)。所以就像你现在看到的那样,我们需要15块宽度和高度的砖块。

几个月前我从0-14开始使用两个循环。我写了自己的长代码来获得所有这些34x34砖块。但是我没有使用任何存储所有值的数组。

现在我有一个一维数组,因为带位锁的元帅副本和位图数据是将所有像素的值快速复制到数组的最佳方法。

而是我站在面对面与问题如何得到那么34元一排低,另外一个知道在35水平将有自己的初始值的另一块砖..

PS。编辑我的帖子,如果事情不好。

很少有人会说“首先制作任何测试代码”。我尝试过,但我得到的只是垃圾,我真的不知道该怎么做。


此方法用于将图像裁剪为包含砖块的较小图像。但我不希望存储砖的小图像。我需要存储在字节数组中的值。

下,有一个证明。

private void OCropImage(int ii, int jj, int p, int p2) 


    { 
     ////We took letter and save value to binnary, then we search in dictionary by value 
     this.rect = new Rectangle(); 
     this.newBitmap = new Bitmap(this.bitmap); 
     for (ii = 0; ii < p; ii++) 
     { 
      for (jj = 0; jj < p2; jj++) 
      { 
       ////New bitmap 
       this.newBitmap = new Bitmap(this.bitmap); 

       ////Set rectangle working area with letters 
       this.rect = new Rectangle(jj * this.miniszerokosc, ii * this.miniwysokosc, this.miniszerokosc, this.miniwysokosc); 
       ////Cut single rectangle with letter 
       this.newBitmap = this.newBitmap.Clone(this.rect, this.newBitmap.PixelFormat); 
       ////Add frame to rectangle to delet bad noise 
       this.OAddFrameToCropImage(this.newBitmap, this.rect.Width, this.rect.Height); 
       this.frm1.SetIm3 = (System.Drawing.Image)this.newBitmap; 

       ////Create image with letter which constains less background 
       this.newBitmap = this.newBitmap.Clone(this.GetAreaLetter(this.newBitmap), this.newBitmap.PixelFormat); 
       ////Count pixels in bitmap 
       this.workingArea = this.GetBinnary(this.newBitmap); 

       var keysWithMatchingValues = this.alphabetLetters.Where(x => x.Value == this.workingArea).Select(x => x.Key); 
       foreach (var key in keysWithMatchingValues) 
       { 
        this.chesswords += key.ToString(); 
       } 
      } 

      this.chesswords += Environment.NewLine; 
      var ordered = this.alphabetLetters.OrderBy(x => x.Value); 
     } 
    } 

PS2。对不起我的英文,如果需要的话请纠正。

+0

你真正的问题是什么? – misha

回答

0

如果我得到你的权利,那么,如果你有这样

p00|p01|p02|... 
---+---+------- 
p10|p11|p12|... 
---+---+------- 
p20|p21|p22|... 
---+---+---+--- 
...|...|...|... 

图像存储在阵列中的左到右行扫描是这样的:

p00,p01,...,p0n, p10,p11,...,p1n, p20,p21, ... 

如果我正确地理解了你,你想要做的是,从图像中取一个给定的矩形(来自具有一定宽度和高度的特定x和y)。下面是代码来做到这一点,有解释:

byte[] crop_area (byte[] source_image, int image_width, int image_height, 
int start_x, int start_y, int result_width, int result_height) 
{ 
    byte[] result = new byte[result_width * result_height]; 
    int endX = x + result_width; 
    int endY = y + result_height; 

    int pos = 0; 

    for (int y = startY; y < endY; y++) 
     for (int x = startX; x < endX; x++) 
     { 
      /* To get to the pixel in the row I (starting from I=1), we need 
      * to skip I-1 rows. Since our y indexes start from row 0 (not 1), 
      * then we don't need to subtract 1. 
      * 
      * So, the offset of the pixel at (x,y) is: 
      * 
      *  y * image_width  +  x 
      * |-----------------------| |-----------------| 
      * Skip pixels of y rows Offset inside row 
      */ 
      result[pos] = source_image[y * image_width + x]; 

      /* Advance to the next pixel in the result image */ 
      pos++; 
     } 
    return result; 
} 

然后,取该块中的行I和J列在(I,J = 0,...,14)做:

crop_area (source_image, image_width, image_height, J*image_width/15, I*image_height/15, image_width/15, image_height/15) 
+0

我认为这将是答案,但我会检查出tommorow :)感谢您的帮助! :) – deadfish

+0

是的,这就是(说什么更多?) – deadfish

+0

嘿,但我有字节数组,它存储的值bitmapdata.sride * bitmap.height,什么是假设操作呢?图像是10x10不会给出结果100:| – deadfish