Gtk::Image and HiDPI

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Gtk::Image and HiDPI

Kasper Peeters-2
When I set the content of a Gtk::Image from a pixbuf, gtk seems to be
scaling up the visible size by the HiDPI scale factor. That is, if I
feed it a pixbuf of 100x100 pixels, on a screen with scale factor 2, it
will be upscaled to cover 200x200 device pixels, making it blocky.

Is there any way in which I can tell gtk not to do that, so that when I
feed it a 200x200 image, it will actually draw it at 200x200 device
pixels, not 400x400 device pixels?

Thanks,
Kasper
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Gtk::Image and HiDPI

Debarshi Ray-2
On Fri, Feb 08, 2019 at 07:40:06PM +0000, Kasper Peeters wrote:
> When I set the content of a Gtk::Image from a pixbuf, gtk seems to be
> scaling up the visible size by the HiDPI scale factor. That is, if I
> feed it a pixbuf of 100x100 pixels, on a screen with scale factor 2, it
> will be upscaled to cover 200x200 device pixels, making it blocky.
>
> Is there any way in which I can tell gtk not to do that, so that when I
> feed it a 200x200 image, it will actually draw it at 200x200 device
> pixels, not 400x400 device pixels?

Try using a Cairo surface (or cairo_surface_t) with the appropriate
scaling factor (see cairo_surface_set_device_scale).

A GdkPixbuf doesn't have a scaling factor attached to it, but a Cairo
surface does. Generally speaking, these days there's a trend to move
towards the latter wherever possible and makes sense.
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Gtk::Image and HiDPI

Kasper Peeters-2
> Try using a Cairo surface (or cairo_surface_t) with the appropriate
> scaling factor (see cairo_surface_set_device_scale).
>
> A GdkPixbuf doesn't have a scaling factor attached to it, but a Cairo
> surface does. Generally speaking, these days there's a trend to move
> towards the latter wherever possible and makes sense.

I tried using a Gtk::DrawingArea instead of my Gtk::Image, and then used
the following override of 'DrawingArea::on_draw' to draw my pixbuf onto
the Cairo surface provided by the DrawingArea:

-----
bool MyArea::on_draw(const Cairo::RefPtr<Cairo::Context>& cr)
   {
   if(!pixbuf) return false;

   auto surface = cr->get_target();
   auto csurface = surface->cobj();
   cairo_surface_set_device_scale(csurface, 1.0, 1.0);
   Gdk::Cairo::set_source_pixbuf(cr, pixbuf, 0, 0);
   cr->paint();
   }
-----

Unfortunately, the inclusion of that 'cairo_surface_set_device_scale'
makes the widget go black completely, unless the scale factor already
was 1.0.

So this is probably not what you meant... Can you give me a pointer?

Thanks,
Kasper

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Gtk::Image and HiDPI

Debarshi Ray-2
On Mon, Feb 11, 2019 at 09:48:05AM +0000, Kasper Peeters wrote:

> > Try using a Cairo surface (or cairo_surface_t) with the appropriate
> > scaling factor (see cairo_surface_set_device_scale).
> >
> > A GdkPixbuf doesn't have a scaling factor attached to it, but a Cairo
> > surface does. Generally speaking, these days there's a trend to move
> > towards the latter wherever possible and makes sense.
>
> I tried using a Gtk::DrawingArea instead of my Gtk::Image, and then used
> the following override of 'DrawingArea::on_draw' to draw my pixbuf onto
> the Cairo surface provided by the DrawingArea:

This should also work. There must be something wrong in your code.

> So this is probably not what you meant... Can you give me a pointer?

I meant gtk_image_set_from_surface and gtk_image_new_from_surface. You
can convert the GdkPixbuf to a Cairo surface using things like
gdk_cairo_surface_create_from_pixbuf.
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list