Solved: GDK Pixbuff

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
exagonx
Posts: 314
Joined: Mar 20, 2009 17:03
Location: Italy
Contact:

Solved: GDK Pixbuff

Post by exagonx »

Hello
Hello everyone.

Using GTK as a Framework there is the need to insert images, photos or other graphic formats to display, this is GTK_Image, currently alone it can only display an image, but in some cases you need to resize it to be inserted in an elegant or comfortable way inside the work window.

Like this code:

Code: Select all

gtk_image_set_from_pixbuf(GTK_IMAGE(ViewImage), pixbuf)
after some misunderstanding about my request, TJF proceeded to give me an example on how to apply the function.

Code: Select all

'Code explained by TJF 

VAR height = 200, fnam = "myfile.png"
DIM AS GError PTR errr
VAR pixbuf = gdk_pixbuf_new_from_file_at_scale(fnam, -1, height, TRUE, @errr)

IF 0 = errr THEN
  gtk_image_set_from_pixbuf(GTK_IMAGE(ViewImage), pixbuf)
ELSE
  ?"Loading image failed: "; *errr->message
  g_error_free(errr)
  gtk_quit()
  
END IF
'Thank you TJF
Thank you.
Last edited by exagonx on Nov 14, 2020 11:03, edited 2 times in total.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: GDK Pixbuff

Post by TJF »

What are you asking for?

GdkPixbuf is a structure holding Information that describes an image. It's not made for rezising.

Assuming you're talking about Gtk3:
I'd load the image in a cairo surface, scale (share, rotate) it and afterwards call gtk_image_set_from_surface(GTK_IMAGE(ViewImage), cairo_surface).

Regards

@Admin:
This is not a Linux specific topic. Can you please move it to section Libraries.
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: GDK Pixbuff

Post by caseih »

GDKPixbuf does have a scale utility, though:

https://developer.gnome.org/gdk-pixbuf/ ... aling.html
exagonx
Posts: 314
Joined: Mar 20, 2009 17:03
Location: Italy
Contact:

Re: GDK Pixbuff

Post by exagonx »

TJF wrote:What are you asking for?

GdkPixbuf is a structure holding Information that describes an image. It's not made for rezising.

Assuming you're talking about Gtk3:
I'd load the image in a cairo surface, scale (share, rotate) it and afterwards call gtk_image_set_from_surface(GTK_IMAGE(ViewImage), cairo_surface).
.
Thank you for the answer TJF

Its a way to know header and how use it for resize all image to the specific size ?
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: GDK Pixbuff

Post by TJF »

Sorry, my first post was faulty.

The cairo solution is limited to .png files (but provides better quality and more flexibility).

As caseih mentioned GdkPixbuf is sufficient to load and scale images (I confused GdkPixbuf with the depercated GdkImage object), like:

Code: Select all

' ...

VAR height = 32, fnam = "MyImage.jpg"
DIM AS GError PTR errr
VAR pixbuf = gdk_pixbuf_new_from_file_at_scale(fnam, -1, height, TRUE, @errr)

IF 0 = errr THEN
  gtk_image_set_from_pixbuf(GTK_IMAGE(ViewImage), pixbuf)
ELSE
  ?"Loading image failed: "; *errr->message
  g_error_free(errr)
  gtk_quit()
END IF
@exagonx
I dislike the way you're asking / cooperating.
exagonx
Posts: 314
Joined: Mar 20, 2009 17:03
Location: Italy
Contact:

Re: GDK Pixbuff

Post by exagonx »

Hi TJF Thank you for explain its very usefull



TJF wrote:Sorry, my first post was faulty.

@exagonx
I dislike the way you're asking / cooperating.
I'm sorry, unfortunately I don't know a different way to express myself, English is not my language.
In any case feel free to correct me this will make you more friendly in my eyes.
Post Reply