-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to get the RGBA imge data ,i do this,but get nothing #189
Comments
Could you pls send a complete code snippet, including all declarations? |
double x[] = { 0, 0.2, 0.4, 0.6, 0.8, 1.0 }; /* Draw something into the memory using GR / // 'RGBA' winrt::array_view clr(vvc); |
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);
} |
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] });
}
}
The text was updated successfully, but these errors were encountered: