Skip to content
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

Open
cyberdstar opened this issue Aug 29, 2024 · 6 comments
Open

how to get the RGBA imge data ,i do this,but get nothing #189

cyberdstar opened this issue Aug 29, 2024 · 6 comments

Comments

@cyberdstar
Copy link

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] });
}
}

@jheinen
Copy link
Collaborator

jheinen commented Aug 29, 2024

Could you pls send a complete code snippet, including all declarations?

@cyberdstar
Copy link
Author

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 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] });
}
}

winrt::array_view clr(vvc);
bitmap_image bi;
CanvasBitmap bp = CanvasBitmap::CreateFromColors(sender, clr, width, height);
Windows::Foundation::Numerics::float3x2 transform = Windows::Foundation::Numerics::make_float3x2_scale(sender.ActualWidth() / width, sender.ActualHeight() / height);
args.DrawingSession().Transform(transform);
args.DrawingSession().DrawImage(bp, 0, 0);
free(data);

@jheinen
Copy link
Collaborator

jheinen commented Aug 29, 2024

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);
}

@cyberdstar
Copy link
Author

rgba
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 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] });
}
}

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

@cyberdstar
Copy link
Author

think very much. i use msvc lib get noting,but with Windows (MinGW),get the correct result

@IngoMeyer441
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants