Change background color of TAchart series - delphi

i Have this code for drawing a profile of one plane figure.
Chart1.Series.Clear;
Lser:=TLineSeries.Create(Chart1);
for x:= 1 to 20 do
Lser.AddXY(strtofloat(stringgrid1.Cells[1,x]),strtofloat(stringgrid1.Cells[2,x]));
chart1.AddSeries(Lser);
lser.LinePen.Width:=2;
lser.SeriesColor:=clred;
Now, how can change the background color of my plane figure?
Thank you very much
if u see the picture, i want draw only the yellow area (i fill it on paint of windows)

Thanks to all, i solved it with TAreaSeries.

chart1.Backwall.Transparent := False;
chart1.Backwall.Color := clgreen;

Related

Delphi TBitMap transparency from ImageList to a button

I am trying to create a custom icon button with a transparent bitmap image, below the code.
The icon is stored in an ImageList connected to an ActionList.
bitmap := TBitmap.Create;
BmpObj := TMemoryStream.Create;
try
ImageList.GetBitmap(ActionList.Actions[i].ImageIndex, bitmap);
bitmap.Transparent := TRUE;
bitmap.TransparentColor := clWhite;
bitmap.Canvas.Brush.Color := clWhite;
bitmap.SaveToStream(BmpObj);
finally
BmpObj.Free;
bitmap.Free;
end;
I don't know what I am missing.. Anyone has an idea about this problem?
Without better knowledge about the components I asked about, I show the basic way of having transparent image on many Windows controls.
Take a TImageList and fill it with the images you want to use. The lower left pixel determines the transparent color. In my example black numbers are placed on white background.
On the button, set property Images to your ImageList and ImageIndex to a valid image number (0 .. ). The image will appear on the button, with the white colored areas transparent.
In the image below, I include a TImage with the bitmap so you can see the actual colors.
Note no code required.

How to avoid changing background color of a chart with TeeChart Pro 2017 in Delphi10?

I'm using this code to draw a cross on my chart based on my mouse position
//Setup color
Canvas.Pen.Style := psSolid;
Canvas.Pen.Width := 1;
CrossSize := 30;
Canvas.Pen.Mode := pmNotXor;
Canvas.Pen.Color := clGray;
//Draw the cross
Canvas.MoveTo(X - CrossSize, Y);
Canvas.LineTo(X + CrossSize, Y);
Canvas.MoveTo(X, Y - CrossSize);
Canvas.LineTo(X, Y + CrossSize);
If the Pen.Mode is pmNotXor, my chart background color is changed to light gray when my mouse moved out of the chart.
If the Pen.Mode is pmXor, the background color turns black.
This code works perfectly with an older version of TChart and Delphi XE4. I only have this issue when upgrading our software to Delphi10 and TeeChart Pro 2017.
Following is a screen shoot of this issue.
White background vs after moving the cursor (which trigger the draw a cross function) Gray background.
Does anyone has any idea what am I using wrong here or is it a bug related to Delphi 10?
Regards,
Vu
This is similar to Victoria's answer, but is the way I do it.
var
SavePen: TPen;
begin
SavePen := TPen.Create;
try
SavePen.Assign( Canvas.Pen );
// modify the pen
Canvas.Pen.Assign( SavePen );
finally
SavePen.Free;
end;
end;
It is arguable whether the assignment back to the canvas Pen should be inside the finally clause. Your choice, really.

Change HUE of a Bitmap but retain background color?

I have been experimenting with the Change HUE/Saturation example found on the EFG website: http://www.efg2.com/Lab/Library/Delphi/Graphics/Color.htm
I want to use the techniques found in that example to change the color values of some bitmaps (to be used on a TImage). There is one problem I am facing, and that is with TImages that have transparent bitmaps; I don't want the background color to change its HUE but rather just the actual image data.
Take this sample image we can work with (though any image with transparency can be used):
Download the Change HUE/Saturation demo from the link at the top.
Now Load the button image above into the ImageOriginal.
Set the Delta Saturation to 1.
Run the Project.
Some output results:
What I would like to happen here is keep the original background color (defined by the bottom left most pixel) and only adjust the hue for the rest of the image. So, the output results would actually look like this (edited in Paint.NET):
Allow me to use another sample image to test with that contains more image data:
As before with the first image sample, the results could be something like:
When the results I desire should be like so:
One idea I had was after the HUE change, replace the bottom left most color with the color from the original, but I am not sure if this is the correct approach or not, and even if it is I am not sure how to replace color X for another color. (Graphics and Math is beyond me).
For example, if I drew two blue color circles on Mickey's ear (the blue been the original transparent color from bottom left most pixel) and also colored his eyes:
Changing the HUE again may look like:
when in fact it should like this:
Simply put I would like to change the HUE of an image whether it be by the methods used from the EFG demo or another solution. The transparent color as defined by the bottom most left pixel should not be changed when the HUE is changed, this should remain the same as demonstrated in the sample images.
How can I change the HUE of a bitmap whilst retaining the background color?
The code you refer walks all pixels on the image to change hue/saturation. You can modify the code so that it does not interfere if a pixel has a specific color:
PROCEDURE TFormChangeHS.UpdateBitmap;
..
S : TReal;
V : TReal;
FixColor: TRGBTriple; // New variable
BEGIN
DeltaSaturation := SpinEditDeltaSaturation.Value;
NewHue := TrackBarHue.Position;
Bitmap := TBitmap.Create;
TRY
Bitmap.Width := ImageOriginal.Width;
Bitmap.Height := ImageOriginal.Height;
Bitmap.PixelFormat := ImageOriginal.Picture.Bitmap.PixelFormat;
ASSERT(Bitmap.PixelFormat = pf24bit);
// save bottom left color
FixColor := PRGBTripleArray(
ImageOriginal.Picture.Bitmap.ScanLine[Bitmap.Height - 1])^[0];
//--
FOR j := 0 TO Bitmap.Height-1 DO
BEGIN
RowIn := ImageOriginal.Picture.Bitmap.Scanline[j];
RowOut := Bitmap.Scanline[j];
FOR i := 0 TO Bitmap.Width-1 DO
BEGIN
WITH RowIn[i] DO
BEGIN
// copy the color to target and continue with next iteration
if (RowIn[i].rgbtBlue = FixColor.rgbtBlue) and
(RowIn[i].rgbtGreen = FixColor.rgbtGreen) and
(RowIn[i].rgbtRed = FixColor.rgbtRed) then begin
RowOut[i] := FixColor;
Continue;
end;
//--
// convert pixel coordinates to HSV
RGBtoHSV(rgbtRed, rgbtGreen, rgbtBlue, H, S, V);
END;
..
..
Output:  
In theory, you can for example:
First, you have to determine what is the background... (probably picking the color of a specific pixel like delphi does...)
Then, with this background color, you can create a mask based on this color...
You duplicate the image... apply the hue...
You merge your 2 bitmaps using the mask...

Zooming with mouse: marquee color

When I use zooming with mouse on a chart (TeeChart) (left button and drag bottom right) cursor draws a marquee rectangle for zoom area. Marquee line is barely visible in light-grey color. Is there any way to change the color of marquee line (something like black, red etc) to make it more contrast and easy to see?
I'm using VCL TChart 4.04.
I think this is not possible in TChart v.4.04, or at least haven't found any property which might do this.
At least in TChart v.8.03 (the one shipped with Delphi 2009) there are properties TChart.Zoom.Brush and TChart.Zoom.Pen where you can set the colors and other properties for the selection rectangle. So, if you would have the newer version of TChart you might use something like this:
procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.Zoom.Pen.Width := 2;
Chart1.Zoom.Pen.Color := clRed;
end;

Confusion with CreatePolygonRgn

I am working with delphi. I have an array of points which are continues as shown in image.
Then I give this array to CreatePolygonRgn and create the region say rgn1.
rgn1 := CreatePolygonRgn(tmpary1[0],Count,WINDING);
Then I fill the region and show it on my TImage control as shown in image. The problem is from the left side, the points are also covered in region but from right side the points of array are not covered. This can be seen in image that from left side green border is not shown but from right side border is visible. Am I mistaking somewhere??? If my question is not clear to you then please ask.
Thank You.
Edit:
for cnt := 0 to Count - 1 do begin
p1 := imgmain.Picture.Bitmap.ScanLine[tmpary[cnt].Y];
p1[tmpary[cnt].X].rgbtBlue := 0;
p1[tmpary[cnt].X].rgbtGreen := 255;
p1[tmpary[cnt].X].rgbtRed := 0;
end;
rgn1 := CreatePolygonRgn(tmpary1[0],tmpseq1.Count,WINDING);
imgmain.Picture.Bitmap.Canvas.Brush.Color := clRed;
FillRgn(imgmain.Picture.Bitmap.Canvas.Handle,rgn1,imgmain.Picture.Bitmap.Canvas.Brush.Handle);
It may just be the way it works. FillRect, for example, includes the left and top borders, but excludes the right and bottom borders of the rectangle.
I think the same probably applies to FillRgn.
Edit: Confirmed here, too.
At last I found the feasible solution to my problem and also the solution of this problem as both question are related to each other.
I was filling the region and then tried to get boundary of that region. I was getting some points of original array as boundary and some points were actual boundary points. I wanted all points of actual boundary.
So, now I fill the region with red color then fill the pixels of array with red color and then I run floodfill algorithm. It will give all points I needed.

Resources