Code:
function CreateGradient(const aIndex: Integer): TImageBuffer;
begin
if aIndex = 0 then
begin
// Here is the famous blue gradient used by default in Pinax
Result := CreateGradientImage(50,80,LINEAR_Y,NO_NOISE,[
NewData(1.00,RGB($00, $11, $33),RGB($00, $55, $77))
]);
end
else
if aIndex = 1 then
begin
// Here is a glassy button background and the code used to create it.
// Notice the use of an HSV colour space to keep
// consistent hue and saturation and only vary the value.
Result := CreateGradientImage(200, 40,LINEAR_Y,NO_NOISE,[
NewData(0.5,HSV(0.55, 0.2, 0.40),HSV(0.55, 0.2, 0.54)),
NewData(1.0,HSV(0.55, 0.2, 0.47),HSV(0.55, 0.2, 0.61))
]);
end
else
if aIndex = 2 then
begin
// This is an example of a subtle radial gradient combined with a Gaussian noise texture
Result := CreateGradientImage(480, 100,RADIAL(0.5, 0.0),GAUSSIAN(0.01),[
NewData(0.8,RGB($22, $22, $22),RGB($00, $00, $00))
]);
end
else
if aIndex = 3 then
begin
// And finally here is a textured linear gradient inspired by Ryan Berg's
// on http://djangofriendly.com/.
Result := CreateGradientImage(200, 350, LINEAR_Y, GAUSSIAN(0.01),[
NewData(0.5,RGB($01, $10, $09),RGB($09, $2D, $1F))
]);
end;
end;
procedure TForm1.Button_CreateGradientClick(Sender: TObject);
var
x,y: Integer;
ImageBuffer: TImageBuffer;
Colour: TRGB;
begin
ImageBuffer := CreateGradient(RadioGroup_Gadients.ItemIndex);
Image_Gradient.Width := ImageBuffer.Width;
Image_Gradient.Height := ImageBuffer.Height;
Image_Gradient.Picture.Bitmap.Width := ImageBuffer.Width;
Image_Gradient.Picture.Bitmap.Height := ImageBuffer.Height;
for y := 0 to ImageBuffer.Height - 1 do
for x := 0 to ImageBuffer.Width - 1 do
begin
Colour := ImageBuffer.Pixels[y,x];
Image_Gradient.Picture.Bitmap.Canvas.Pixels[x,y] := Windows.RGB(Colour.r,Colour.g,Colour.b);
end;
Image_Gradient.Invalidate;
Image_Gradient.Picture.SaveToFile('Gradient'+IntToStr(RadioGroup_Gadients.ItemIndex)+'.bmp');
end;
I have to post the actual unit code in the next post as it pushes this post over 10000 characters!
Bookmarks