我从剪贴板获取一个CF_DIB
,然后调用:
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(info->bmiColors, GDK_COLORSPACE_RGB, TRUE, 8, info->bmiHeader.biWidth, info->bmiHeader.biHeight, rowstride, NULL, NULL);
从像素数据中创建GdkPixbuf。然而,图像似乎被颠倒了,镜像颠倒了(我认为它是BGR)。
如何正确创建pixbuf?
发布于 2019-06-24 08:48:39
我用我写的这个函数解决了我的问题:
GdkPixbuf* soft_drm_dib_to_pixbuf (BITMAPINFO* info)
{
gint rowstride = 4 * ((info->bmiHeader.biBitCount * info->bmiHeader.biWidth + 31) / 32);
gsize size = rowstride * info->bmiHeader.biHeight;
gchar* copy = (gchar *)info->bmiColors;
gchar* newp = g_malloc0(size);
gint x = 0;
gint y = 0;
for(y = 0; y < info->bmiHeader.biHeight; y++)
{
for(x = 0; x < info->bmiHeader.biWidth; x++)
{
gint col = x;
gint row = info->bmiHeader.biHeight - y - 1;
gint index = (row * info->bmiHeader.biWidth + col) * 4;
gint index2 = (row * info->bmiHeader.biWidth + (info->bmiHeader.biWidth - col)) * 4;
newp[(size - index2) + 0] = copy[index + 2];
newp[(size - index2) + 1] = copy[index + 1];
newp[(size - index2) + 2] = copy[index + 0];
}
}
return gdk_pixbuf_new_from_data(newp, GDK_COLORSPACE_RGB, TRUE, 8, info->bmiHeader.biWidth, info->bmiHeader.biHeight, rowstride, (GdkPixbufDestroyNotify)g_free, NULL);
}
不过,它绝对可以看起来更好。
https://stackoverflow.com/questions/56727077
复制相似问题