/* * Image Converter * --------------- * This program tests the loading and saving of * images. */ #include /* GraphApp 2.3 image */ /* depth = 8 */ /* width = 11 */ /* height = 11 */ /* cmapsize = 4 */ rgb downarr_cmap [] = { 0xFFFFFFFF, 0x009C9CFF, 0x00000000, 0x00000000, }; byte downarr_pixels [] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00, 0x00, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x01, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; imagedata downarr_imagedata = { 8, /* depth */ 11, /* width */ 11, /* height */ 4, /* cmapsize */ downarr_cmap, downarr_pixels }; image downarr_image = & downarr_imagedata; char * filename = NULL; image img = NULL; button btn = NULL; void load_an_image(button b) { image prev; window win = parentwindow(b); filename = askfilename(NULL, filename); if (filename) { setcursor(WatchCursor); prev = img; img = loadimage(filename); if (img) { setimage(btn, img); resize(btn, rect(10,50, getwidth(img)+4, getheight(img)+4)); delimage(prev); } setcursor(ArrowCursor); } } void save_an_image(button b) { filename = askfilesave(NULL, filename); if (filename) { setcursor(WatchCursor); saveimage(img, filename); setcursor(ArrowCursor); } } void main(void) { rect r = rect(0,0,200,200); window w = newwindow("Image Converter", rect(50,50,400,350), StandardWindow); newbutton("Load...", rect(10,10,90,30), load_an_image); newbutton("Save As...", rect(110,10,90,30), save_an_image); btn = newimagebutton(downarr_image, rect(10,50,15,15), NULL); show(w); }