我从剪贴板中获得了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?
答案 0 :(得分:0)
我通过编写的此函数解决了我的问题:
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);
}
它看起来肯定会好很多。