Re: drawing a generated bitmap



On Sun, Jun 18, 2006 at 11:28:31AM +0000, kamil stachowski wrote:
> > Don't draw pixel by pixel, it would be awfully slow.
> > Use GdkPixbufs and gdk_draw_pixbuf().
> 
> you mean "don't draw pixel by pixel using drawpoint", is that it?

Yes, I do -- and I still mean it.

> however, i ran into a problem with colourmaps. i was using gdk.image (has the 
> putpixel method which treats the colours in a more traditional way, and seems 
> to be fast enough for my needs) but didn't manage to change the colours it 
> uses. i keep getting a blue gradient which is not precisely what i want.
> here's the code:
> 
> def img=Image(ImageType.Fastest,Visual.System,500,500);
> for (mutable x=0, x<500; x++) for (mutable y=0; y<500; y++)
> 	img.PutPixel(x,y,(x+y):>UInt32);
> 		
> def gc=GC(args.Event.Window);
> mutable col=Color(0xff,0,0);
> gc.Colormap.AllocColor(ref col,true,true);
> img.Colormap=gc.Colormap;
> 
> args.Event.Window.DrawImage(gc,img,0,0,0,0,500,500);
> 
> i don't seem to be able to spot anything red in the result. could you please 
> tell me what i am doing wrong?

Well, I can't speak Nemerle, but as far as I understand it,
you first fill the image with arbitrary values no one knows
which color they correspond to in the colormap, then
allocate one very dark red color (full red is 0xffff in
Gdk) but never use it -- the `pixel' field filled by
AllocColor is the value to use with PutPixel -- and after
all that you set the image's colormap.

To draw you have to allocate the colors *first* -- and note
if the display is not direct/true-color, it has a limited
number of colors and you will not be able to allocate a new
color for each unique (x+y):>UInt32 value.

So, please save yourself all the hassle and just use
GdkPixbuf.

Yeti


--
Anonyms eat their boogers.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]