如何在for循环中获得3次数组?

时间:2022-05-02 22:33:57

I am not familiar with c/c++, but when I am trying to implement a for loop statement I have the following error:

我不熟悉c / c ++,但是当我尝试实现for循环语句时,我遇到以下错误:

error C2296: '*' : illegal, left operand has type 'unsigned char *'

错误C2296:'*':非法,左操作数的类型为'unsigned char *'

unsigned char *_Orgin_Pixel_;
unsigned char *_Copy_Pixel_;
....

for (unsigned int i = 0; i < Picture_x_ * Picture_y_; i++)
{
    *(_Copy_Pixel_*3 + i) = _Orgin_Pixel_[i];
}

How do I resolve that problem?

我该如何解决这个问题?

1 个解决方案

#1


0  

I resolve this problem. as below,

我解决了这个问题。如下,

for (unsigned int i = 0; i < Picture_x_ * Picture_y_; i++)
{
    *(_Copy_Pixel_ + i * 3 + 0) = _Orgin_Pixel_[i];
    *(_Copy_Pixel_ + i * 3 + 1) = _Orgin_Pixel_[i];
    *(_Copy_Pixel_ + i * 3 + 2) = _Orgin_Pixel_[i];
}

What if I want to separate as 2 cascade, why do they different?

如果我想分成2级联,为什么它们不同呢?

for (unsigned int i = 0; i < Picture_y_ ; i++)
    for (unsigned int j = 0; j < Picture_x_ ; j++)
{
    _Copy_Pixel_[(i*Picture_y_  + j *3+ 0)] = _Orgin_Pixel_[i*Picture_y_ + j];//B
    _Copy_Pixel_[(i*Picture_y_  + j*3 + 1)] = _Orgin_Pixel_[i*Picture_y_ + j];//G
    _Copy_Pixel_[(i*Picture_y_  + j*3 + 2)] = _Orgin_Pixel_[i*Picture_y_ + j];//R
}

I can't understand, did I miss something?

我无法理解,我错过了什么吗?

#1


0  

I resolve this problem. as below,

我解决了这个问题。如下,

for (unsigned int i = 0; i < Picture_x_ * Picture_y_; i++)
{
    *(_Copy_Pixel_ + i * 3 + 0) = _Orgin_Pixel_[i];
    *(_Copy_Pixel_ + i * 3 + 1) = _Orgin_Pixel_[i];
    *(_Copy_Pixel_ + i * 3 + 2) = _Orgin_Pixel_[i];
}

What if I want to separate as 2 cascade, why do they different?

如果我想分成2级联,为什么它们不同呢?

for (unsigned int i = 0; i < Picture_y_ ; i++)
    for (unsigned int j = 0; j < Picture_x_ ; j++)
{
    _Copy_Pixel_[(i*Picture_y_  + j *3+ 0)] = _Orgin_Pixel_[i*Picture_y_ + j];//B
    _Copy_Pixel_[(i*Picture_y_  + j*3 + 1)] = _Orgin_Pixel_[i*Picture_y_ + j];//G
    _Copy_Pixel_[(i*Picture_y_  + j*3 + 2)] = _Orgin_Pixel_[i*Picture_y_ + j];//R
}

I can't understand, did I miss something?

我无法理解,我错过了什么吗?