Open cyberdstar opened 1 month ago
Could you pls send a complete code snippet, including all declarations?
int width = 300;
int height = 300;
unsigned char* data = (unsigned char*)malloc(height * width * 4);
memset(data, 0, height * width * 4);
double x[] = { 0, 0.2, 0.4, 0.6, 0.8, 1.0 }; double y[] = { 0.3, 0.5, 0.4, 0.2, 0.6, 0.7 };
/ Draw something into the memory using GR / // 'RGBA'
char filename[64];
sprintf_s(filename, "!%dx%d@%p.mem", width, height, data);
// gr_setlinewidth(1);
gr_beginprint(filename);
gr_polyline(6, x, y);
gr_endprint();
std::vector
}
}
winrt::array_view
The following example works as expected. I used this include file, to save the byte array as a (transparent) PNG file.
/*
cc -I /usr/local/gr/include tmem.c \
-L/usr/local/gr/lib -lGR -Wl,-rpath,/usr/local/gr/lib
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gr.h"
#include "svpng.inc"
int main(void)
{
char filename[64];
int i, width = 500, height = 500;
unsigned char *data;
double x[] = { 0, 0.2, 0.4, 0.6, 0.8, 1.0 };
double y[] = { 0.3, 0.5, 0.4, 0.2, 0.6, 0.7 };
data = (unsigned char *) malloc(height * width * 4);
memset(data, 0, height * width * 4);
sprintf(filename, "!%dx%d@%p.mem", width, height, data);
gr_beginprint(filename);
gr_polyline(6, x, y);
gr_endprint();
FILE *fp = fopen("rgba.png", "wb");
svpng(fp, width, height, data, 1);
fclose(fp);
}
double x[] = { 0, 0.2, 0.4, 0.6, 0.8, 1.0 }; double y[] = { 0.3, 0.5, 0.4, 0.2, 0.6, 0.7 };
/ Draw something into the memory using GR / // 'RGBA'
char filename[64];
sprintf_s(filename, "!%dx%d@%p.mem", width, height, data);
gr_setlinewidth(3);
gr_beginprint(filename);
gr_polyline(6, x, y);
gr_endprint();
std::vector
}
}
FILE* fp = fopen("rgba.png", "wb");//严重性 代码 说明 项目 文件 行 禁止显示状态 详细信息 //错误 C4996 'fopen': This function or variable may be unsafe.Consider using fopen_s instead.To disable deprecation, use _CRT_SECURE_NO_WARNINGS.See online help for details.WaveFrontExperts E : \pwork\ky\WaveFrontExperts\MainWindow.xaml.cpp 157
svpng(fp, width, height, data, 1); fclose(fp);
I do this,but still get a dark png not a curve imge
think very much. i use msvc lib get noting,but with Windows (MinGW),get the correct result
So you downloaded a pre-compiled version of GR on Windows?
It would be interesting for us to investigate, why the MSVC version behaves differently.
double x[] = { 0, 0.2, 0.4, 0.6, 0.8, 1.0 }; double y[] = { 0.3, 0.5, 0.4, 0.2, 0.6, 0.7 }; / Draw something into the memory using GR / // 'RGBA' // gr_openws(0, 0, 100); char filename[64]; sprintf_s(filename, "!%dx%d@%p.mem", width, height, data); // gr_setlinewidth(1); gr_beginprint(filename); gr_polyline(6, x, y); gr_endprint(); std::vector vvc;
for (int j = 0; j < height; j++)
{
unsigned char pdata = &data[width 4 j];
for (uint64_t i = 0; i < (width 4); i = i + 4)
{
vvc.push_back({pdata[i + 3],pdata[i + 0],pdata[i + 1] ,pdata[i + 2] });
}
}