Hi, is it possible to use a Gdk::Pixbuf which consists of i.e 10x10 pixels of a red colour? Inside DrawingArea this is easy, but I would like to use simple Pixbufs which have different colours
on 2007-09-23 03:21
on 2007-09-24 11:29
Marc Heiler wrote: > Hi, > > is it possible to use a Gdk::Pixbuf which consists of i.e 10x10 pixels > of a red colour? > Inside DrawingArea this is easy, but I would like to use simple Pixbufs > which have different colours > Try: pb = Gdk::Pixbuf.new(Gdk::Pixbuf::COLORSPACE_RGB, false, 8, 10, 10) pb.fill!(0xff0000ff) Just in case it interests anyone, here's an example that uses basic Gdk::Pixbuf functions to draw a red rectangle around a specified region of the image & reduce the saturation of the surrounding image: ---8<--- require 'gdk_pixbuf2' Rect = Struct.new("Rect", :x, :y, :w, :h) file = ARGV[0] || '/home/geoff/Desktop/iStock/iStock_000001958797XSmall.jpg' pb = Gdk::Pixbuf.new(file) # Sample crop area crop = Rect.new(pb.width / 4, pb.height / 4, pb.width / 2, pb.height / 2) # Make pixbuf red (for border) red_pb = pb.dup red_pb.fill!(0xff0000ff) # Make greyed out/pixelated pixbuf for background grey_pb = pb.saturate_and_pixelate(0.2, true) # Box for border box = Rect.new(crop.x - 2, crop.y - 2, crop.w + 4, crop.h + 4) # Ensure that border doesn't overflow image box.x = [box.x,0].max box.y = [box.y,0].max box.w = [box.w, red_pb.width - box.x].min box.h = [box.h, red_pb.height - box.y].min # Use red pixbuf as border background red_pb.copy_area(box.x, box.y, box.w, box.h, grey_pb, box.x, box.y) # Copy pristine image into the crop area pb.copy_area(crop.x, crop.y, crop.w, crop.h, grey_pb, crop.x, crop.y) pb = grey_pb pb.save(file + '.out.jpeg', 'jpeg', :quality => 80) ---8<--- ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
on 2007-09-24 17:40
Whoa, cool stuff ... in fact looks like a "filter" for a dungeon-like map on some images, reminds me of old indiana jones game in a dark maze :) And thanks by the way!
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.