GTK-PIXBUF

#include <gtk/gtk.h>
#include <stdlib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>

#define DA_WIDTH 300
#define DA_HEIGHT 300
#define SCALE_FACTOR 1.2

#define PEN_MOVE  0
#define PEN_UP    1
#define PEN_DOWN  2


GdkPixmap *pixmap = NULL;
GtkWidget *window, *vbox, *tool_bar, *drawing_area;

gboolean status;
gboolean fdiscard = TRUE;

gint prev_x, prev_y;
GdkGC *my_gc_red;
GdkColor color;

struct ImageData {
  GtkWidget *drawing_area;
  int width, height;
  GdkPixbuf *pixbuf;
  float scale;
};

struct ImageData data;

static void expose_cb(GtkWidget *da, GdkEventExpose *event, struct ImageData *data)
{
    GdkPixbuf *pixbuf;
    gfloat ratio;
    gint s_width, s_height, w_width, w_height;
    s_width = gdk_pixbuf_get_width (data->pixbuf);
    s_height = gdk_pixbuf_get_height (data->pixbuf);
    w_width = data->width;
    w_height = data->height;

    if ((gfloat) w_width / s_width > (gfloat) w_height / s_height) {
        ratio = (gfloat) w_height / s_height;
      } else {
        ratio = (gfloat) w_width / s_width;
      }

    int width  = s_width  * ratio;
    int height = s_height * ratio;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值