Mis*_*ash 0 c++ arrays syntax syntax-error
我有一个功能,需要两个图像输入(图像和图像2),逐个像素地混合颜色值.因子表示图像中颜色值的百分比,因此其余值(1因子)来自image2.我有无符号字符表示的像素缓冲区,我很难弄清楚我需要什么语法才能访问和设置我的值.我尝试了很多东西,但是现在它给了我以下错误:
filters.C:91:41: error: scalar object ‘p’ requires one element in initializer
unsigned char *p = {red, green, blue};
Run Code Online (Sandbox Code Playgroud)
功能:
void Filter::Execute()
{
if (input->GetWidth() == input2->GetWidth() && input->GetHeight() == input2->GetHeight())
{
int width = input->GetWidth();
int height = input->GetHeight();
output.ResetSize(width, height);
for (int w = 0; w < width; w++)
{
for (int h = 0; h < height; h++)
{
unsigned char red = input->GetPixel(w, h)[0]*factor+input2->GetPixel(w, h)[0]*(1-factor);
unsigned char green = input->GetPixel(w, h)[1]*factor+input2->GetPixel(w, h)[1]*(1-factor);
unsigned char blue = input->GetPixel(w, h)[2]*factor+input2->GetPixel(w, h)[2]*(1-factor);
unsigned char *p = {red, green, blue};
output.SetPixel(w, h, p);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我设置图像类的方法:
#include <image.h>
#include <stdlib.h>
Image::Image()
{
width = 0;
height = 0;
buffer = NULL;
}
Image::~Image()
{
if (buffer != NULL)
{
delete[] buffer;
}
}
void Image::ResetSize(int w, int h)
{
width = w;
height = h;
if (buffer != NULL)
{
delete[] buffer;
}
else
{
buffer = new unsigned char[3*width*height];
}
}
unsigned char * Image::GetPixel(int w, int h)
{
int index = h*width + w;
return buffer+3*index;
}
void Image::SetPixel(int w, int h, unsigned char *p)
{
int index = h*width + w;
buffer[3*index+0] = p[0];
buffer[3*index+1] = p[1];
buffer[3*index+2] = p[2];
}
Run Code Online (Sandbox Code Playgroud)
我在俯瞰什么?
nne*_*neo 10
unsigned char *它不是一个数组,它是一个指针.你想宣布它
unsigned char p[] = {red, green, blue};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
891 次 |
| 最近记录: |