To: md5i at cs.cmu.edu Cc: lablgtk at kaba.or.jp Subject: Re: Bitmaps from pixmaps: Is what I am trying to do possible? In-Reply-To: References: Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20011004184414U.garrigue at kurims.kyoto-u.ac.jp> Date: Thu, 04 Oct 2001 18:44:14 +0900 From: Jacques Garrigue Lines: 40 From: md5i@cs.cmu.edu > The following program fails with a message about: > > Gdk-ERROR **: BadMatch (invalid parameter attributes) > serial 116 error_code 8 request_code 62 minor_code 0 > > due, apparently, to the fact that gdk doesn't like drawing a pixmap > (of depth > 1) onto a bitmap. Is there any other good way to get a > mask based on a particular color of a pixmap? > > Desired result: a bitmap consisting of the pixels of style2.xpm which > are t_color. Since you cannot read directly from a pixmap, you must first get a snapshot image of it, then build the corresponding mask: let pixmap = GDraw.pixmap_from_xpm ~file:"style2.xpm" ();; let width, height = pixmap#size;; let img = Gdk.Image.get pixmap#pixmap ~x:0 ~y:0 ~width ~height;; let t_color = GDraw.color (`RGB(0xc000,0xc000,0xc000));; let pixel = Gdk.Color.pixel t_color;; let mask = match pixmap#mask with Some m -> m | None -> assert false;; let omask = new GDraw.drawable mask in for x = 0 to width - 1 do for y = 0 to height - 1 do let col = if Gdk.Image.get_pixel img ~x ~y = pixel then `BLACK else `WHITE in omask#set_foreground col; omask#point ~x ~y done done;; let w = GWindow.window ~show:true ();; let dr = new GDraw.drawable w#misc#window;; dr#set_clip_mask mask;; dr#put_pixmap 0 0 pixmap#pixmap;; Remark that you may have to change a bit some function calls as I am using a development version. Cheers, Jacques Garrigue