当前位置:网站首页>GTK RGB图像绘制
GTK RGB图像绘制
2022-08-02 02:17:00 【百口可乐__】
源代码
#include <gtk/gtk.h>
#define WIDTH 300
#define HEIGHT 300
GtkWidget *window;
GdkPixbuf *pixbuf;
GtkWidget *image;
int main() {
gtk_init(NULL, NULL);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), WIDTH, HEIGHT);
gtk_window_set_title(GTK_WINDOW(window), "RgbaShow");
guchar rgbbuf[WIDTH *HEIGHT * 3];
guchar *pos;
pos = rgbbuf;
for (int y = 0; y < HEIGHT; y++)
{
for (int x = 0; x < WIDTH; x++)
{
*pos++ = x<WIDTH/2?100:200; /* Red. */
*pos++ = y<HEIGHT/2?200:150; /* Green. */
*pos++ = 207; /* Blue. */
}
}
pixbuf = gdk_pixbuf_new_from_data(rgbbuf, GDK_COLORSPACE_RGB, FALSE, 8, WIDTH, HEIGHT, WIDTH*3, NULL, NULL);
image = gtk_image_new_from_pixbuf(pixbuf);
gtk_container_add(GTK_CONTAINER(window),image);
gtk_widget_show_all(window);
g_signal_connect(G_OBJECT(window),"destroy",G_CALLBACK(gtk_main_quit),NULL);
gtk_main();
}
编译
g++ t.c `pkg-config --cflags --libs gtk+-2.0`
运行
边栏推荐
- Handwritten Blog Platform ~ Day Two
- Install mysql using docker
- Simple example of libcurl accessing url saved as file
- 2022-08-01 mysql/stoonedb慢SQL-Q18分析
- Yunhe Enmo: Let the value of the commercial database era continue to prosper in the openGauss ecosystem
- AOF rewrite
- Chopper webshell feature analysis
- bool框架::PosInGrid (const简历:关键点kp, int &posX, int诗句)
- Oracle19c安装图文教程
- The first time I wrote a programming interview question for Niu Ke: input a string and return the letter with the most occurrences of the string
猜你喜欢
Outsourcing worked for three years, it was abolished...
[Server data recovery] Data recovery case of server Raid5 array mdisk disk offline
"NetEase Internship" Weekly Diary (2)
MySQL优化策略
Data transfer at the data link layer
Safety (2)
Hiring a WordPress Developer: 4 Practical Ways
手写一个博客平台~第三天
Power button 1374. Generate each character string is an odd number
The underlying data structure of Redis
随机推荐
『网易实习』周记(三)
LeetCode Brushing Diary: 74. Searching 2D Matrix
Ringtone 1161. Maximum In-Layer Elements and
Centos7 install postgresql and enable remote access
力扣、752-打开转盘锁
to-be-read list
Talking about the "horizontal, vertical and vertical" development trend of domestic ERP
记一个gorm初始化的坑
A good book for newcomers to the workplace
2022年NPDP考完多久出成绩?怎么查询?
TKU remembers a single-point QPS optimization (I wish ITEYE is finally back)
Nanoprobes丨1-mercapto-(triethylene glycol) methyl ether functionalized gold nanoparticles
数据链路层的数据传输
Hash collisions and consistent hashing
Chengdu openGauss user group recruit!
拼多多借力消博会推动国内农产品品牌升级 看齐国际精品农货
Garbage Collector CMS and G1
工程师如何对待开源
Safety (2)
libcurl访问url保存为文件的简单示例