View Full Version : Changing RGB

03-02-2006, 06:17 PM
Hello. How im able to draw pictures with different rgb's?

03-02-2006, 06:28 PM
You?_Tre question doesn?_Tt make much sense, do you mean using palettes or color modulation or something?

Robert Kosek
03-02-2006, 07:18 PM
I'm assuming that you are meaning draw a greyscale image using an RGB color?

03-02-2006, 07:56 PM
Hello. How im able to draw pictures with different rgb's?
Turn off the grayscale mode (http://en.wikipedia.org/wiki/Grayscale) of your monitor. This will show color picture (http://en.wikipedia.org/wiki/Oil_painting) instead of black and white (http://en.wikipedia.org/wiki/Black-and-white_warbler). You may need to acquire a different monitor, if your current monitor does not have the mentioned feature.

04-02-2006, 10:36 AM
Hello. How im able to draw pictures with different rgb's?

Hi Jonne,

You have numerous options available to you. The first and simplest way is to use the pixels property of the TDXDraw surface, like this:-


You can also fill an area of the surface, like this:-

dst : TRect;


In both examples, aColor is a colour value. I'm not sure whether they operate exactly like Delphi's standard TColor, where you specify the colour value in hex like this:- $bbggrr where bb, gg and rr are the values for Blue, Green and Red respectively. I think they may flip the Blue and Red around to the more traditional $rrggbb notation.

You also have another option for drawing on the TDXDraw surface. You can use a TDXImageList, that you load with images (this can be done at design time or dynamically at runtime). To get started, put the images into the TDXImageList at design time as its easier. Then, you can do this:-


I use a pattern value of 0 as I have no idea what it does yet. This will draw the image in the image list at position 0 to the surface with its top left corner at xPos,Ypos on the surface. There are lots of different variations on this method that allow you to incorporate alpha blending and other effects.

And last but not least, the TDXDraw surface also has a fairly standard TCanvas property allowing you to plot lines, text, arcs. etc.

with dXDraw1.Surface.Canvas do
Brush.Style := bsClear;
Font.Color := clWhite;
Font.Size := 8;
Font.name:='Courier New';

TextOut(0,0,'Hello World');


You must remember to release the canvas when you've finished using it.

So, bringing this all together, you might have something like this in a TDXTimer onTimer event:-

if dxdraw1.canDraw then
dxdraw1.surface.fill(0); // Clear the draw area


with dxdraw1.surface.canvas do
// Use the canvas here

dxdraw1.flip; // You must have doFlip in the options to use this

You don't have to use flip, but using it makes for a smoother display since the user only sees the new screen when you've finished drawing it. But you must have the doFlip option set in the TDXDraw options. If you are using unDelphiX, to enable hardware acceleration, you should have the following options set to true:- do3D, doDirectX7Mode and doHardware.

You may also want to check out all the examples that come with unDelphiX. They are quite useful.

I hope this helps.

05-02-2006, 01:23 AM
He means that image is multiplied with a color.

Here's discussion about improved undelphix and how it can be done:

It makes this kind of command possible:
DrawAlphaCol(Surface, DestRect, PatternIndex, RGB(0,255,0), Alpha);
That would draw grayscale image as green, red or blue image as black and so on...

Edit: Made this small demonstration :wink:
This uses only 1 TDXImageList item, only colors them with alpha weakening when going down.


05-02-2006, 10:45 AM

I figured he wanted something else, because after I posted I read about Netsoccer. But still, worth my time posting, because now I've learned something :-)