免费图像写入像素
freeimage write to pixels
我正在尝试使用freeimage在文件中写入一些顶点(但我也对使用stb_image的解决方案持开放态度(。
我正在尝试使用《计算机图形学:原理与实践》第三版第3章中的代码,清单3.6。
我不知道如何处理免费图片库。
即使我设置了一个红色的背景色,我收到的却是黑色。
此外,即使我使用setpixelcolor
写入文件,我仍然会收到一个黑窗口。顶点应显示为绿点。
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <FreeImage.h>
typedef struct Point
{
float x, y, z;
}Point;
int main()
{
int width = 400;
int height = 300;
int bpp = 24;
FreeImage_Initialise();
FIBITMAP *img = FreeImage_Allocate(width, height, bpp);
RGBQUAD color;
if (!img)
exit(1);
// build a table of vertices
int nbOfPoints = 8;
int nbOfEdges = 12;
float vertices[nbOfPoints][3] =
{
{-0.5, -0.5, 2.5},
{-0.5, 0.5, 2.5},
{0.5, 0.5, 2.5},
{0.5, -0.5, 2.5},
{-0.5, -0.5, 3.5},
{-0.5, 0.5, 3.5},
{0.5, 0.5, 3.5},
{0.5, -0.5, 3.5}
};
// build a table of edges
int edges[nbOfEdges][2] =
{
{0, 1},
{1, 2},
{2, 3},
{3, 0},
{0, 4},
{1, 5},
{2, 6},
{3, 7},
{4, 5},
{5, 6},
{6, 7},
{7, 4}
};
float xmin = -0.5;
float xmax = 0.5;
float ymin = -0.5;
float ymax = 0.5;
Point *pictureVertices = new Point[nbOfPoints * width * height];
float scale = 100;
BYTE *pixelData = NULL;
RGBQUAD backg_color;// = new RGBQUAD(Color.Red);
backg_color.rgbRed = 1.0;
backg_color.rgbGreen = 0;
backg_color.rgbBlue = 0;
FreeImage_SetBackgroundColor(img, &backg_color);
for (int j = height-1; j >= 0; --j)
{
for (int i = 0; i < width; ++i)
{
for (int p = 0; p < nbOfPoints; ++p)
{
float x = vertices[p][0];
float y = vertices[p][1];
float z = vertices[p][2];
float xprime = x / z;
float yprime = y / z;
pictureVertices[p].x = scale * (1.0 - (xprime - xmin) / (xmax - xmin));
pictureVertices[p].y = scale * (yprime - ymin) / (ymax - ymin);
color.rgbRed = 0;
color.rgbGreen = 1.0;
color.rgbBlue = 0;
FreeImage_SetPixelColor(img, pictureVertices[p].x, pictureVertices[p].y, &color);
//FreeImage_SetPixelIndex(img, (int)pictureVertices[i].x, (int)pictureVertices[i].y, pixelData);
}
}
}
FreeImage_Save(FIF_PNG, img, "test.png", 0);
FreeImage_DeInitialise();
std::cout << "n";
return 0;
}
您应该使用0..255的范围,而不是0..1:(
相关文章:
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 访问随机图像像素的快速方法,最多一次
- 计算另一个图像像素满足条件的像素值的平均值
- 如何返回定义良好的内存部分?例如来自图像数据的像素的颜色值
- 如何将像素图像导入cpp
- OpenCV-如何将vale添加到图像一部分的所有像素
- 访问和更改基于另一个图像的像素颜色-opencv c++
- 免费图像写入像素
- 可视化 如何获取图像中像素的颜色(以C++ (sfml) 为单位)
- 将像素打包在盒子中的 1 位/带宽/二进制图像中
- 如何使用 openCV 更改图像每个像素的颜色
- 使用 ImageMagick 从像素强度数组创建灰度图像时遇到问题
- 如何从C 中的CV :: MAT图像中有效提取某些像素
- OPENCV C .在for循环中在不同的图像像素上绘制一个圆圈(应在每个循环运行时将图像打开)
- 图像分割 - 删除C 中不需要的像素
- 如何使用Imebra库将压缩像素(用我自己的编码器压缩)回到DICOM图像文件中
- 如何确定 BMP 图像是否包含来自标题的 BGR 或 BGRA 像素
- 如何使用opencv在不丢失像素的情况下对图像进行去扭曲
- 内存中一个像素图像数据的表示形式
- 如何显示已保存在文件中的像素图像