[gtk/image-loading: 39/70] Add gdk_texture_save_to_png_bytes




commit 4c5fe24bcd52914c64c1399f1675733054334020
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Sep 13 14:29:31 2021 -0400

    Add gdk_texture_save_to_png_bytes
    
    Just expose what we already have available
    internally, so e.g. tests can use it without
    static linking.

 gdk/gdktexture.c | 29 ++++++++++++++++++++++++++++-
 gdk/gdktexture.h |  2 ++
 2 files changed, 30 insertions(+), 1 deletion(-)
---
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index c9dfa77617..a21b62849f 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -657,7 +657,8 @@ gdk_texture_get_render_data (GdkTexture  *self,
  * This is a utility function intended for debugging and testing.
  * If you want more control over formats, proper error handling or
  * want to store to a `GFile` or other location, you might want to
- * look into using the gdk-pixbuf library.
+ * use [method@Gdk.Texture.save_to_png_bytes] or look into the
+ * gdk-pixbuf library.
  *
  * Returns: %TRUE if saving succeeded, %FALSE on failure.
  */
@@ -680,3 +681,29 @@ gdk_texture_save_to_png (GdkTexture *texture,
 
   return result;
 }
+
+/**
+ * gdk_texture_save_to_png_bytes:
+ * @texture: a `GdkTexture`
+ *
+ * Store the given @texture in memory as a PNG file.
+ * Use [ctor@Gdk.Texture.new_from_bytes] to read it back.
+ *
+ * If you want to serialize a texture, this is a convenient and
+ * portable way to do that.
+ *
+ * If you need more control over the generated image, such as
+ * attaching metadata, you should look into an image handling
+ * library such as the gdk-pixbuf library.
+ *
+ * Returns: a newly allocated `GBytes` containing PNG data
+ *
+ * Since: 4.6
+ */
+GBytes *
+gdk_texture_save_to_png_bytes (GdkTexture *texture)
+{
+  g_return_val_if_fail (GDK_IS_TEXTURE (texture), NULL);
+
+  return gdk_save_png (texture);
+}
diff --git a/gdk/gdktexture.h b/gdk/gdktexture.h
index fa04135a90..a8e6c32099 100644
--- a/gdk/gdktexture.h
+++ b/gdk/gdktexture.h
@@ -88,6 +88,8 @@ void                    gdk_texture_download_float             (GdkTexture
 GDK_AVAILABLE_IN_ALL
 gboolean                gdk_texture_save_to_png                (GdkTexture      *texture,
                                                                 const char      *filename);
+GDK_AVAILABLE_IN_4_6
+GBytes *                gdk_texture_save_to_png_bytes          (GdkTexture      *texture);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]