static void save_pixbuf (GdkPixbuf *pixbuf, const char *path, const char *video_path, int size, gboolean is_still) { int width, height; GdkPixbuf *with_holes; GError *err = NULL; gboolean ret; height = gdk_pixbuf_get_height (pixbuf); width = gdk_pixbuf_get_width (pixbuf); /* If we're outputting a gallery or a raw image without a size, * don't scale the pixbuf or add borders */ if (gallery != -1 || (raw_output != FALSE && size == -1)) with_holes = g_object_ref (pixbuf); else if (raw_output != FALSE) with_holes = scale_pixbuf (pixbuf, size, TRUE); else with_holes = scale_pixbuf (pixbuf, size, is_still); if (jpeg_output == FALSE) { char *a_width, *a_height; a_width = g_strdup_printf ("%d", width); a_height = g_strdup_printf ("%d", height); ret = gdk_pixbuf_save (with_holes, path, "png", &err, "tEXt::Thumb::Image::Width", a_width, "tEXt::Thumb::Image::Height", a_height, NULL); } else { ret = gdk_pixbuf_save (with_holes, path, "jpeg", &err, NULL); } if (ret == FALSE) { if (err != NULL) { g_print ("totem-video-thumbnailer couldn't write the thumbnail '%s' for video '%s': %s\n", path, video_path, err->message); g_error_free (err); } else { g_print ("totem-video-thumbnailer couldn't write the thumbnail '%s' for video '%s'\n", path, video_path); } g_object_unref (with_holes); return; } #ifdef THUMB_DEBUG show_pixbuf (with_holes); #endif g_object_unref (with_holes); }
void expedia_snip ( const gchar *file ) { /* Load the pixbuf */ GError *gx = NULL; GdkPixbuf *old, *cropped; gint width, height; old = gdk_pixbuf_new_from_file ( file, &gx ); if (gx) { g_warning ( _("Couldn't open EXPEDIA image file (right after successful download! Please report and delete image file!): %s"), gx->message ); g_error_free ( gx ); return; } width = gdk_pixbuf_get_width ( old ); height = gdk_pixbuf_get_height ( old ); cropped = gdk_pixbuf_new_subpixbuf ( old, WIDTH_BUFFER, HEIGHT_BUFFER, width - 2*WIDTH_BUFFER, height - 2*HEIGHT_BUFFER ); gdk_pixbuf_save ( cropped, file, "png", &gx, NULL ); if ( gx ) { g_warning ( _("Couldn't save EXPEDIA image file (right after successful download! Please report and delete image file!): %s"), gx->message ); g_error_free ( gx ); } g_object_unref ( cropped ); g_object_unref ( old ); }
static nsresult WriteImage(const nsCString& aPath, gfxIImageFrame* aImage) { nsCOMPtr<nsIImage> img(do_GetInterface(aImage)); if (!img) return NS_ERROR_NOT_AVAILABLE; #ifndef MOZ_WIDGET_GTK2 return NS_ERROR_NOT_AVAILABLE; #else nsCOMPtr<nsIGdkPixbufImage> pixImg(do_QueryInterface(img)); if (!pixImg) return NS_ERROR_NOT_AVAILABLE; GdkPixbuf* pixbuf = pixImg->GetGdkPixbuf(); if (!pixbuf) return NS_ERROR_NOT_AVAILABLE; gboolean res = gdk_pixbuf_save(pixbuf, aPath.get(), "png", NULL, NULL); aImage->UnlockImageData(); g_object_unref(pixbuf); return res ? NS_OK : NS_ERROR_FAILURE; #endif }
static void save_itdb_thumb (Itdb_Track *track, GdkPixbuf *pixbuf, guint id) { char *filename; gint width; gint height; g_object_get (G_OBJECT (pixbuf), "width", &width, "height", &height, NULL); filename = g_strdup_printf ("%03d_%s-%s-%s-%xx%x-%016"G_GINT64_MODIFIER"x.png", id, track->artist, track->album, track->title, width, height, track->dbid); if (filename == NULL) { return; } g_print (" %s\n", filename); gdk_pixbuf_save (pixbuf, filename, "png", NULL, NULL); gdk_pixbuf_unref (pixbuf); /* g_print ("Saved %s\n", filename); */ g_free (filename); }
static void save_pixbuf (GdkPixbuf *pixbuf, const char *path, const char *video_path, int size, gboolean is_still) { GdkPixbuf *with_holes; GError *err = NULL; gboolean ret; /* If we're outputting a gallery or a raw image without a size, * don't scale the pixbuf or add borders */ if (gallery != -1 || (raw_output != FALSE && size == -1)) with_holes = g_object_ref (pixbuf); else if (raw_output != FALSE) with_holes = scale_pixbuf (pixbuf, size, TRUE); else with_holes = scale_pixbuf (pixbuf, size, is_still); ret = gdk_pixbuf_save (with_holes, path, "jpeg", &err, NULL); if (ret == FALSE) { if (err != NULL) { g_print ("totem-video-thumbnailer couldn't write the thumbnail '%s' for video '%s': %s\n", path, video_path, err->message); g_error_free (err); } else { g_print ("totem-video-thumbnailer couldn't write the thumbnail '%s' for video '%s'\n", path, video_path); } g_object_unref (with_holes); return; } g_object_unref (with_holes); }
void yui_viewer_save(YuiViewer * yv) { GtkWidget * file_selector; gint result; char * filename; int rowstride; file_selector = gtk_file_chooser_dialog_new ("Please choose a file", NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); gtk_widget_show(file_selector); result = gtk_dialog_run(GTK_DIALOG(file_selector)); switch(result) { case GTK_RESPONSE_ACCEPT: rowstride = yv->w * 4; rowstride += (rowstride % 4)? (4 - (rowstride % 4)): 0; filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(file_selector)); gdk_pixbuf_save(yv->pixbuf, filename, "png", NULL, NULL); break; case GTK_RESPONSE_CANCEL: break; } gtk_widget_destroy(file_selector); }
int grab_window(int src_x, int src_y, int width, int height) { GdkWindow *window, *root; #ifndef GTK3 window = gdk_window_foreign_new(GDK_ROOT_WINDOW()); root = gdk_window_foreign_new(GDK_ROOT_WINDOW()); #else GdkDisplay *gdpy = gdk_display_get_default(); window = root = gdk_x11_window_foreign_new_for_display(gdpy, GDK_ROOT_WINDOW()); #endif GdkPixbuf *screenshot; GError *error = NULL; if (src_x + width > gdk_screen_width ()) width = gdk_screen_width () - src_x; if (src_y + height > gdk_screen_height ()) height = gdk_screen_height () - src_y; time_t now; time(&now); char path[MAXPATHLEN]; snprintf(path, sizeof(path), "%s%i%s", "./screen-shot-window", now, ".png"); printf("%s\n", path); #ifndef GTK3 screenshot = gdk_pixbuf_get_from_drawable (NULL, root, NULL, src_x, src_y, 0, 0, width, height); #else screenshot = gdk_pixbuf_get_from_window(root, src_x, src_y, width, height); #endif printf("----------------%d\n", gdk_pixbuf_get_rowstride(screenshot)); gdk_pixbuf_save (screenshot, path, "png", &error, "tEXt::CREATOR", "gnome-panel-screenshot", NULL); return 0; }
static void dump_thumbs (Itdb_PhotoDB *db, Itdb_Artwork *artwork, const gchar *album_name, const gchar *dir) { GList *it; gint i = 0; GList *thumbnails; thumbnails = itdb_thumb_to_pixbufs (db->device, artwork->thumbnail); for (it = thumbnails; it != NULL; it = it->next, i++) { gchar *filename, *path; GdkPixbuf *pixbuf; pixbuf = GDK_PIXBUF (it->data); g_return_if_fail (pixbuf); filename = g_strdup_printf ("%s-%d-%d.png", album_name, artwork->id, i ); path = g_build_filename (dir, filename, NULL); g_free (filename); gdk_pixbuf_save (pixbuf, path, "png", NULL, NULL); g_object_unref (pixbuf); g_free (path); } g_list_free (thumbnails); }
gboolean pixbuf_to_file_as_jpg(GdkPixbuf *pixbuf, const gchar *filename, gint quality) { GError *error = NULL; gchar *qbuf; gboolean ret; if (!pixbuf || !filename) return FALSE; if (quality == -1) quality = 75; if (quality < 1 || quality > 100) { printf("Jpeg not saved, invalid quality %d\n", quality); return FALSE; } qbuf = g_strdup_printf("%d", quality); ret = gdk_pixbuf_save(pixbuf, filename, "jpeg", &error, "quality", qbuf, NULL); g_free(qbuf); if (error) { printf("Error saving jpeg to %s\n%s\n", filename, error->message); g_error_free(error); } return ret; }
static gboolean save_image_png (const gchar *filename, GdkPixbuf *pixbuf, GError **error) { gchar *contents = NULL; gchar *contents_encode = NULL; gsize length; gboolean ret; gint len; /* get icc file */ ret = g_file_get_contents (ICC_PROFILE, &contents, &length, error); if (!ret) goto out; contents_encode = g_base64_encode ((const guchar *) contents, length); ret = gdk_pixbuf_save (pixbuf, filename, "png", error, "tEXt::Software", "Hello my name is dave", "icc-profile", contents_encode, NULL); len = strlen (contents_encode); g_debug ("ICC profile was %i bytes", len); out: g_free (contents); g_free (contents_encode); return ret; }
gboolean media_art_file_to_jpeg (const gchar *filename, const gchar *target) { GdkPixbuf *pixbuf; GError *error = NULL; /* TODO: Add resizing support */ pixbuf = gdk_pixbuf_new_from_file (filename, &error); if (error) { g_clear_error (&error); return FALSE; } else { gdk_pixbuf_save (pixbuf, target, "jpeg", &error, NULL); g_object_unref (pixbuf); if (error) { g_clear_error (&error); return FALSE; } } return TRUE; }
static GdkPixbuf * skin_get_thumbnail (const gchar * path) { gchar * thumbname = get_thumbnail_filename (path); GdkPixbuf * thumb = NULL; if (g_file_test (thumbname, G_FILE_TEST_EXISTS)) { thumb = gdk_pixbuf_new_from_file (thumbname, NULL); if (thumb) goto DONE; } thumb = skin_get_preview (path); if (! thumb) goto DONE; audgui_pixbuf_scale_within (& thumb, 128); if (thumb) gdk_pixbuf_save (thumb, thumbname, "png", NULL, NULL); DONE: g_free (thumbname); return thumb; }
int svg_to_png(const char* file, const char* dest) { if (!gdk_init_check(NULL, NULL)) { g_warning("Init gdk environment failed"); return -1; } GError* error = NULL; RsvgHandle* handler = rsvg_handle_new_from_file(file, &error); if (error) { g_warning("New RsvgHandle failed: %s", error->message); g_error_free(error); return -1; } GdkPixbuf* pbuf = rsvg_handle_get_pixbuf(handler); g_object_unref(G_OBJECT(handler)); error = NULL; gdk_pixbuf_save(pbuf, dest, "png", &error, NULL); g_object_unref(G_OBJECT(pbuf)); if (error) { g_warning("Save to png file failed: %s", error->message); g_error_free(error); return -1; } return 0; }
static void headerview_save_contact_pic (HeaderView *headerview, MsgInfo *msginfo) { #ifndef USE_ALT_ADDRBOOK gchar *filename = NULL; GError *error = NULL; GdkPixbuf *picture = NULL; if (!gtk_widget_get_visible(headerview->hbox)) return; if (headerview->image) { picture = gtk_image_get_pixbuf(GTK_IMAGE(headerview->image)); } filename = addrindex_get_picture_file(msginfo->from); if (!filename) return; if (!is_file_exist(filename)) { gdk_pixbuf_save(picture, filename, "png", &error, NULL); if (error) { g_warning("Failed to save image: %s", error->message); g_error_free(error); } } g_free(filename); #else /* new address book */ #endif }
void SaveImage (PtrSimulation simulation) { printf ("Entrez le prefixe des fichiers images :\n"); char prefix[250]; scanf ("%s", prefix); PtrGroundArea ground_area = simulation_get_ground_area (simulation); PtrGroundAreaEnergyMapNavigator ground_area_energy_map_navigator = simulation_get_energy_map_navigator (simulation); assert (ground_area != NULL); assert (ground_area_energy_map_navigator != NULL); ground_area_energy_map_navigator_move_position (ground_area_energy_map_navigator, 0); int count_energy_map = ground_area_energy_map_navigator_get_count (ground_area_energy_map_navigator); int i = 0; for (i = 0; i < count_energy_map; i++) { char filename[255]; sprintf (filename, "%s_%d.png", prefix, i); GdkPixbuf* picture = ground_area_to_pixbuf (ground_area); PtrGroundAreaEnergyMap ground_area_energy_map = ground_area_energy_map_navigator_get_current (ground_area_energy_map_navigator); picture = ground_area_energy_map_to_pixbuf (picture, ground_area_energy_map); gdk_pixbuf_save (picture, filename, "png", NULL, NULL); ground_area_energy_map_navigator_move_next (ground_area_energy_map_navigator); } ground_area_energy_map_navigator_move_position (ground_area_energy_map_navigator, 0); printf("Images sauvegardee.\n"); }
void WebBrowserObject::BrowserSnapshot(const char *fname) { int width, height; char *c, *buf = 0; GdkColormap *cmap = gdk_colormap_get_system(); gdk_drawable_get_size(GDK_DRAWABLE(mozilla->window), &width, &height); GdkPixbuf *pix = gdk_pixbuf_get_from_drawable(0, GDK_DRAWABLE(mozilla->window), cmap, 0, 0, 0, 0, width, height); if (pix) { if (!fname) { buf = strdup(location ? location : "lmboxweb"); buf = (char*)realloc(buf, strlen(buf) + 16); fname = buf; if ((c = strrchr(buf, '/'))) { //fname = c + 1; } if ((c = strrchr(fname, '.'))) { *c = 0; } strcat((char*)fname, ".png"); } gdk_pixbuf_save (pix, fname, "png", NULL, NULL); gdk_pixbuf_unref(pix); printf("Webbrowser snapshot %s\n",fname); } gdk_colormap_unref(cmap); lmbox_free(buf); }
gboolean eel_gdk_pixbuf_save_to_file (const GdkPixbuf *pixbuf, const char *file_name) { return gdk_pixbuf_save ((GdkPixbuf *) pixbuf, file_name, "png", NULL, NULL); }
gboolean media_art_file_to_jpeg (const gchar *filename, const gchar *target, GError **error) { GdkPixbuf *pixbuf; GError *local_error = NULL; /* TODO: Add resizing support */ pixbuf = gdk_pixbuf_new_from_file (filename, &local_error); if (local_error) { g_propagate_error (error, local_error); return FALSE; } gdk_pixbuf_save (pixbuf, target, "jpeg", &local_error, NULL); g_object_unref (pixbuf); if (local_error) { g_propagate_error (error, local_error); return FALSE; } return TRUE; }
gboolean f_pixbuf_save_jpeg_atomic (GdkPixbuf *pixbuf, const char *file_name, int quality, GError **error) { char *tmp_file_name = g_strconcat (file_name, ".tmp", NULL); char *quality_string = g_strdup_printf ("%d", quality); gboolean success; if (! gdk_pixbuf_save (pixbuf, tmp_file_name, "jpeg", error, "quality", quality_string, NULL)) { success = FALSE; goto end; } if (rename (tmp_file_name, file_name) != 0) { char *error_message = g_strdup_printf ("Atomic rename failed: %s", g_strerror (errno)); g_set_error (error, GDK_PIXBUF_ERROR, GDK_PIXBUF_ERROR_FAILED, error_message); g_free (error_message); success = FALSE; goto end; } success = TRUE; end: g_free (quality_string); g_free (tmp_file_name); return TRUE; }
static void pidgin_whiteboard_button_save_press(GtkWidget *widget, gpointer data) { PidginWhiteboard *gtkwb = (PidginWhiteboard*)(data); GdkPixbuf *pixbuf; GtkWidget *dialog; int result; dialog = gtk_file_chooser_dialog_new (_("Save File"), GTK_WINDOW(gtkwb->window), GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, NULL); /* gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), (gboolean)(TRUE)); */ /* if(user_edited_a_new_document) */ { /* gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), default_folder_for_saving); */ gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "whiteboard.jpg"); } /* else gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), filename_for_existing_document); */ result = gtk_dialog_run(GTK_DIALOG(dialog)); if(result == GTK_RESPONSE_ACCEPT) { char *filename; filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); gtk_widget_destroy(dialog); /* Makes an icon from the whiteboard's canvas 'image' */ pixbuf = gdk_pixbuf_get_from_drawable(NULL, (GdkDrawable*)(gtkwb->pixmap), gdk_drawable_get_colormap(gtkwb->pixmap), 0, 0, 0, 0, gtkwb->width, gtkwb->height); if(gdk_pixbuf_save(pixbuf, filename, "jpeg", NULL, "quality", "100", NULL)) purple_debug_info("gtkwhiteboard", "File Saved...\n"); else purple_debug_info("gtkwhiteboard", "File not Saved... Error\n"); g_free(filename); } else if(result == GTK_RESPONSE_CANCEL) { gtk_widget_destroy(dialog); purple_debug_info("gtkwhiteboard", "File not Saved... Cancelled\n"); } }
static PidginStatusIconTheme * create_icon_theme(GtkWidget *window) { int s, i, j; const char *dirname = g_get_tmp_dir(); PidginStatusIconTheme *theme; const char *author; #ifndef _WIN32 author = getlogin(); #else author = "user"; #endif theme = g_object_new(PIDGIN_TYPE_STATUS_ICON_THEME, "type", "status-icon", "author", author, "directory", dirname, NULL); for (s = 0; sections[s].heading; s++) { GtkWidget *vbox = g_object_get_data(G_OBJECT(window), sections[s].heading); for (i = 0; sections[s].options[i].stockid; i++) { GtkWidget *image = g_object_get_data(G_OBJECT(vbox), sections[s].options[i].stockid); GdkPixbuf *pixbuf = g_object_get_data(G_OBJECT(image), "pixbuf"); if (!pixbuf) continue; pidgin_icon_theme_set_icon(PIDGIN_ICON_THEME(theme), sections[s].options[i].stockid, sections[s].options[i].stockid); for (j = 0; stocksizes[j]; j++) { int width, height; GtkIconSize iconsize; char size[8]; char *name; GdkPixbuf *scale; GError *error = NULL; if (!(sections[s].flags & (1 << j))) continue; iconsize = gtk_icon_size_from_name(stocksizes[j]); gtk_icon_size_lookup(iconsize, &width, &height); g_snprintf(size, sizeof(size), "%d", width); if (i == 0) { name = g_build_filename(dirname, size, NULL); purple_build_dir(name, S_IRUSR | S_IWUSR | S_IXUSR); g_free(name); } name = g_build_filename(dirname, size, sections[s].options[i].stockid, NULL); scale = gdk_pixbuf_scale_simple(pixbuf, width, height, GDK_INTERP_BILINEAR); gdk_pixbuf_save(scale, name, "png", &error, "compression", "9", NULL); g_free(name); g_object_unref(G_OBJECT(scale)); if (error) g_error_free(error); } } } return theme; }
void debug_save_pixbuf(GdkPixbuf *buf) { static int buf_num = 0; char name[20]; /* plenty */ sprintf(name, "__dbg%04d.png", buf_num++); gdk_pixbuf_save(buf, name, "png", NULL, NULL); fprintf(stderr, "saved to %s\n", name); }
int grab_whole_screen() { GdkWindow *window, *root; #ifndef GTK3 window = gdk_window_foreign_new(GDK_ROOT_WINDOW()); root = gdk_window_foreign_new(GDK_ROOT_WINDOW()); #else GdkDisplay *gdpy = gdk_display_get_default(); window = root = gdk_x11_window_foreign_new_for_display(gdpy, GDK_ROOT_WINDOW()); #endif GdkPixbuf *screenshot; gint x_real_orig, y_real_orig; gint x_orig, y_orig; gint real_width, real_height; gint width, height; GError *error = NULL; #ifndef GTK3 gdk_drawable_get_size(window, &real_width, &real_height); #else real_width = gdk_window_get_width(window); real_height = gdk_window_get_height(window); #endif gdk_window_get_origin(window, &x_real_orig, &y_real_orig); x_orig = x_real_orig; y_orig = y_real_orig; width = real_width; height = real_height; if (x_orig < 0) { width = width + x_orig; x_orig = 0; } if (y_orig < 0) { height = height + y_orig; y_orig = 0; } if (x_orig + width > gdk_screen_width ()) width = gdk_screen_width () - x_orig; if (y_orig + height > gdk_screen_height ()) height = gdk_screen_height () - y_orig; char path[MAXPATHLEN]; time_t now; time(&now); snprintf(path, sizeof(path), "%s%i%s", "./screen-shot-whole-screen-", now, ".png"); #ifndef GTK3 screenshot = gdk_pixbuf_get_from_drawable (NULL, root, NULL, x_orig, y_orig, 0, 0, width, height); #else screenshot = gdk_pixbuf_get_from_window(root, x_orig, y_orig, width, height); #endif gdk_pixbuf_save (screenshot, path, "png", &error, "tEXt::CREATOR", "gnome-panel-screenshot", NULL); return 0; }
void capture(GtkWidget *button, gpointer ip) { int cmd, sec; char *file = NULL; char message[1024]; time_t tt; struct tm *tm_ptr = NULL; struct sockaddr_in addr; gint x, y; GdkScreen* cur_screen = NULL; GdkWindow* window = NULL; GdkPixbuf* pixbuf_screenshot = NULL; GdkRectangle rect; GdkRectangle screen_rect; LinpopChat chat; gboolean result; file = (char *)g_malloc(32); inet_aton(ip,&addr.sin_addr); result = getChatByIP(addr,&chat); assert(result == TRUE); time(&tt); tm_ptr = localtime(&tt); strftime(file, 32, "%Y%m%d%H%M%S", tm_ptr); strcat(file, ".jpg"); g_printf("ready to capture.....\r\n"); if (cur_screen == NULL) cur_screen = gdk_screen_get_default (); screen_rect.x = 0; screen_rect.y = 0; screen_rect.width = gdk_screen_get_width (cur_screen); //get screen width screen_rect.height = gdk_screen_get_height (cur_screen); //get screen height g_print("screen_rect: x=%d,y=%d,w=%d,h=%d\n",screen_rect.x,screen_rect.y,screen_rect.width,screen_rect.height); window = gdk_screen_get_root_window (cur_screen); //get window by screen //Window xwin = GDK_WINDOW_XID(window); //get window id //g_print("xwindow id is %x\n",xwin); gdk_window_get_origin (window, &x, &y); //get origin point rect.x = x; rect.y = y; gdk_drawable_get_size (GDK_DRAWABLE (window), &rect.width,&rect.height); //get drawable size g_print("rect: x=%d,y=%d,w=%d,h=%d\n",rect.x,rect.y,rect.width,rect.height); if (! gdk_rectangle_intersect (&rect, &screen_rect, &rect)) { //obtain the intersect area from rect and screen_rect g_print("Capture failed!...\r\n"); printInfoToTextView(chat.showTextView,option.user,"Capture failed!..\n"); return; } g_print("capture rect: x=%d,y=%d,w=%d,h=%d\n",rect.x,rect.y,rect.width,rect.height); pixbuf_screenshot = gdk_pixbuf_get_from_drawable (NULL, window, NULL,rect.x - x, rect.y - y, 0, 0, rect.width, rect.height); //get pixbuf from drawable widget gdk_pixbuf_save (pixbuf_screenshot, file, "jpeg", NULL, "quality","100", NULL); //save pixbuf to jpeg format file g_object_unref (pixbuf_screenshot); //free pixbuf g_print("Capture saved!!!\r\n"); sprintf(message,"%s %s",file,"saved in current director."); printInfoToTextView(chat.showTextView,option.user,message); }
gboolean ada_gdk_pixbuf_save (GdkPixbuf *pixbuf, const char *filename, const char *type, GError **error, char *key, char *value) { return gdk_pixbuf_save (pixbuf, filename, type, error, key, value, NULL); }
/* Verify whether all pixels outside the updated area * have the same values in pixbuf_old and pixbuf_new. */ static gboolean pixbuf_not_changed_outside_area (GdkPixbuf *pixbuf_new, GdkPixbuf *pixbuf_old, int x, int y, int width, int height) { int pixbuf_width, pixbuf_height; int x_curr, y_curr; pixbuf_width = gdk_pixbuf_get_width (pixbuf_new); pixbuf_height = gdk_pixbuf_get_height (pixbuf_new); for (x_curr = 0; x_curr < pixbuf_width; x_curr++) { for (y_curr = 0; y_curr < pixbuf_height; y_curr++) { if ((x_curr >= x) && (x_curr < x + width) && (y_curr >= y) && (y_curr < y + height)) { continue; /* inside area - don't compare pixels. */ } if (get_pixel (pixbuf_new, x_curr, y_curr) != get_pixel (pixbuf_old, x_curr, y_curr)) { printf("Pixel at (%d, %d) changed from %x to %x,\n", x_curr, y_curr, get_pixel (pixbuf_old, x_curr, y_curr), get_pixel (pixbuf_new, x_curr, y_curr)); printf("But it is outside of area with "); printf("x=%d, y=%d, width=%d, height=%d\n", x, y, width, height); #if 0 gdk_pixbuf_save (pixbuf_old, "old.png", "png", NULL, NULL); gdk_pixbuf_save (pixbuf_new, "new.png", "png", NULL, NULL); #endif g_assert_not_reached (); } } } return TRUE; }
void saveFileSignal(GtkWidget * widget, gpointer data) { // Get extension to determine image type std::string filepath(gtk_file_selection_get_filename (GTK_FILE_SELECTION (((_saveData *)data)->fs))); gdk_pixbuf_save(gtk_image_get_pixbuf( ((_saveData *)data)->image), filepath.c_str(), filepath.substr(filepath.rfind('.')+1).c_str(), NULL, "quality", "100", NULL); gtk_widget_destroy(GTK_WIDGET(((_saveData *)data)->fs)); }
static int _snapshot_save(Camera * camera, char const * path, CameraSnapshotFormat format) { struct v4l2_pix_format * pix = &camera->format.fmt.pix; GdkPixbuf * pixbuf; char buf[16]; gboolean res; GError * error = NULL; if((pixbuf = gdk_pixbuf_new_from_data(camera->rgb_buffer, GDK_COLORSPACE_RGB, FALSE, 8, pix->width, pix->height, pix->width * 3, NULL, NULL)) == NULL) return -_camera_error(camera, _("Could not save picture"), 1); switch(format) { case CSF_JPEG: snprintf(buf, sizeof(buf), "%d", camera->snapshot_quality); res = gdk_pixbuf_save(pixbuf, path, "jpeg", &error, "quality", buf, NULL); break; case CSF_PNG: res = gdk_pixbuf_save(pixbuf, path, "png", &error, NULL); break; default: res = FALSE; break; } g_object_unref(pixbuf); if(res != TRUE) { error_set_code(1, "%s: %s", _("Could not save picture"), (error != NULL) ? error->message : _("Unknown error")); g_error_free(error); return -_camera_error(camera, error_get(), 1); } return 0; }
bool ScreenCaptureData::Capture (const char *filename) { XImage *image; int row_stride; int offset; int red_shift = 0, green_shift = 0, blue_shift = 0; guint32 pixel; GdkPixbuf *buffer; GError* error = NULL; image = XGetImage (display, root_window, x, y, width, height, AllPlanes, ZPixmap); if (image == NULL) return false; // Gdk only supports 24 bits RGB // The XImage is (at least on my machine) 32 bits RGB. row_stride = image->bytes_per_line; while (((image->red_mask >> red_shift) & 1) == 0) { red_shift++; } while (((image->green_mask >> green_shift) & 1) == 0) { green_shift++; } while (((image->blue_mask >> blue_shift) & 1) == 0) { blue_shift++; } for (int r = 0; r < image->height; r++) { for (int c = 0; c < image->width; c++) { offset = row_stride * r + c * 4; pixel = *(guint32 *) (image->data + offset); image->data [offset - c + 0] = (pixel & image->red_mask) >> red_shift; image->data [offset - c + 1] = (pixel & image->green_mask) >> green_shift; image->data [offset - c + 2] = (pixel & image->blue_mask) >> blue_shift; } } // Create a new pixbuf from our converted data buffer = gdk_pixbuf_new_from_data ((const guchar *) image->data, GDK_COLORSPACE_RGB, false, 8, image->width, image->height, row_stride, NULL, NULL); // Save to file gdk_pixbuf_save (buffer, filename, "png", &error, "tEXt::CREATOR", "moonlight-test-harness", NULL); gdk_pixbuf_unref (buffer); XDestroyImage (image); return true; }
int main(int argc, char** argv) { GtkWidget *window; int x, y; gtk_init(&argc, &argv); /* window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_opacity(window, 0.7); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), "pressed"); gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER); gtk_widget_show(window); gtk_main(); */ GdkPixbuf* photo = gdk_pixbuf_new_from_file_at_size("bluesky.jpg", 300, 200, NULL); //GdkPixbuf* image = gdk_pixbuf_new_from_data(photo,; //photo = gdk_pixbuf_flip(photo, FALSE); //gdk_pixbuf_fill(photo, 0xff00ff64); //gdk_pixbuf_rotate_simple(photo, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE); //gdk_pixbuf_save(photo, "thumbnail.png", "png", NULL, NULL); guchar *pixels, *p; int rowstride, n_channels, bits, width, height ; GdkColorspace cs; n_channels = gdk_pixbuf_get_n_channels(photo); rowstride = gdk_pixbuf_get_rowstride(photo); pixels = gdk_pixbuf_get_pixels(photo); bits = gdk_pixbuf_get_bits_per_sample(photo); cs = gdk_pixbuf_get_colorspace(photo); width = gdk_pixbuf_get_width(photo); height = gdk_pixbuf_get_height(photo); printf("n_channels %d\n", n_channels); printf("rowstride %d\n", rowstride); printf("bits %d\n", bits); printf("cs %d\n", cs); printf("width %d\n", width); printf("height %d\n", height); //photo = gdk_pixbuf_new_from_data(pixels, cs, TRUE, bits, width, height, rowstride, NULL, NULL); //gdk_pixbuf_add_alpha(photo, FALSE, 0, 0, 0); for(x = 0; x < width; x++) { for(y = 0; y < height; y++) { put_pixel(photo, x, y, 100); } } gdk_pixbuf_save(photo, "thumbnail.jpg", "jpeg", NULL, NULL); return 0; }