我试图将R8G8B8A8图像转换为R8G8B8图像,我现在得到的是图像,但是有很多扫描线,我每个像素的字节数是4个字节,32位。
图像缓冲区的类型为unsigned char [width * height * 4],它是源,目标是unsigned char [width * height * 3]。
int j = 0;
int i = 0;
for (int k = 0; k < (width*height); k++)
{
for(int b = 0; b < 3; b++)
{
dst[i + b] = src[j + b];
}
i+=3;
j+=4;
}
答案 0 :(得分:0)
你可以这样做:
for (int k = 0; k < width*height; k++)
{
for(int b = 0; b < 3; b++)
{
dst[k*3 + b] = src[k*4 + b];
}
}
答案 1 :(得分:0)
目标图像可能需要在4字节边界上对齐的行:
InvalidArgumentError: You must feed a value for placeholder tensor 'yy' with dtype int32
[[Node: yy = Placeholder[dtype=DT_INT32, shape=[], _device="/job:localhost/replica:0/task:0/cpu:0"]()]]
Caused by op 'yy', defined at:
File "/opt/conda/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/opt/conda/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)