继上篇移植成功以后,需要做一个完全由PNG图片组成的程序,其中遇到一些问题.就是如果
GrDrawImageFromFile尺寸参数跟图片尺寸大小不一致,导致无法显示.而且必要时要去掉BGR转RGB的代码.下面贴一下代码,留个纪念.
- #define MWINCLUDECOLORS
-
#include <stdio.h>
-
#include "nano-X.h"
-
#include "mwtypes.h"
-
-
static GR_WINDOW_ID wid;
-
static GR_GC_ID gc, gc1, gc2, gc3, gc4;
-
static GR_IMAGE_INFO image_info;
-
static GR_WINDOW_ID pixmap;
-
static GR_EVENT event;
-
-
static void handleevent(GR_EVENT *);
-
static void doClick(void);
-
-
int main(int ac,char **av){
-
if (GrOpen()<0){
-
printf("Can't open graphics\n");
-
exit(1);
-
}
-
-
gc = GrNewGC();
-
wid = GrNewWindowEx (GR_WM_PROPS_APPWINDOW |
-
GR_WM_PROPS_CAPTION |
-
GR_WM_PROPS_CLOSEBOX,
-
"no title",
-
GR_ROOT_WINDOW_ID, 0, 0,
-
1028,
-
768,
-
MWRGB(0xf, 0, 0));
-
-
GrMapWindow(wid);
-
-
gc1 = GrNewGC();
-
gc2 = GrNewGC();
-
gc3 = GrNewGC();
-
gc4 = GrNewGC();
-
-
GrSetGCForeground(gc1, RED);
-
GrSetGCBackground(gc1, BROWN);
-
GrSetGCForeground(gc2, MAGENTA);
-
GrSetGCMode(gc4, GR_MODE_XOR);
-
-
GrSelectEvents(wid, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE);
-
GrSelectEvents(wid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN);
-
-
while(1){
-
GrCheckNextEvent(&event);
-
handleevent(&event);
-
}
-
return 0;
-
}
-
-
static void handleevent(GR_EVENT *event){
-
switch (event->type){
-
case GR_EVENT_TYPE_BUTTON_DOWN:
-
doClick();
-
break;
-
case GR_EVENT_TYPE_EXPOSURE:
-
break;
-
case GR_EVENT_TYPE_CLOSE_REQ:
-
GrClose();
-
exit(0);
-
break;
-
default:
-
break;
-
}
-
}
-
-
static void doClick(void){
-
GrDrawImageFromFile (wid, gc, 150, -80, 804, 1024, "/mnt/nfs/k.png", 1);
-
GrDrawImageFromFile (wid, gc, -10, -20, 300, 300, "/mnt/nfs/a.png", 1);
-
GrDrawImageFromFile (wid, gc, 100, 600, 48, 48, "/mnt/nfs/2.png", 1);
-
GrText(wid, gc, 750, 100, "fuck", 20, 0);
-
printf("Good!\n");
-
}
阅读(2205) | 评论(0) | 转发(0) |