Skip to content

Image

class cAlgo.API

DesktopCLICloud

Represents the image chart control.

Environment behaviour

CLI — not supported. Accepted without error but never displayed, so control events such as Click are never raised.

Cloud — not supported. Accepted without error but never displayed, so control events such as Click are never raised.

Definition

public class Image : ControlBase

Namespace: cAlgo.API · Group: Controls · Inherits: ControlBase

Examples

Example 1

using cAlgo.API;
using System.IO;

namespace cAlgo
{
    public partial class ImageSample : Indicator
    {
        protected override void Initialize()
        {
            if (!System.IO.File.Exists(ImageFilePath))
            {
                Print($"Image not found: {ImageFilePath}");

                return;
            }

            var imageBytes = System.IO.File.ReadAllBytes(ImageFilePath);

            var image = new Image
            {
                Source = imageBytes,
                Width = 200,
                Height = 200,
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center
            };

            Chart.AddControl(image);
        }

        public override void Calculate(int index)
        {
        }
    }
}
from System.IO import File

if not File.Exists(api.ImageFilePath):
    api.Print(f"Image not found: {api.ImageFilePath}")
else:
    image = Image()
    image.Source = File.ReadAllBytes(api.ImageFilePath)
    image.Width = 200
    image.Height = 200
    image.HorizontalAlignment = HorizontalAlignment.Center
    image.VerticalAlignment = VerticalAlignment.Center
    api.Chart.AddControl(image)
{
  "AccessRights": "FullAccess",
  "TimeZone": "UTC",
  "IsOverlay": true,
  "Parameters": [
    {
      "Name": "ImageFilePath",
      "DisplayName": "Image File Path",
      "Type": "String"
    }
  ]
}

Example 2

using cAlgo.API;

namespace cAlgo.Robots;

public partial class TestExample : Robot
{
    private const string SVG = "<svg width='800px' height='800px' viewBox='0 0 1024 1024' class='icon'  version='1.1' xmlns='http://www.w3.org/2000/svg'><path d='M512 960c-92.8 0-160-200-160-448S419.2 64 512 64s160 200 160 448-67.2 448-160 448z m0-32c65.6 0 128-185.6 128-416S577.6 96 512 96s-128 185.6-128 416 62.4 416 128 416z' fill='#050D42' /><path d='M124.8 736c-48-80 92.8-238.4 307.2-363.2S852.8 208 899.2 288 806.4 526.4 592 651.2 171.2 816 124.8 736z m27.2-16c33.6 57.6 225.6 17.6 424-97.6S905.6 361.6 872 304 646.4 286.4 448 401.6 118.4 662.4 152 720z' fill='#050D42' /><path d='M899.2 736c-46.4 80-254.4 38.4-467.2-84.8S76.8 368 124.8 288s254.4-38.4 467.2 84.8S947.2 656 899.2 736z m-27.2-16c33.6-57.6-97.6-203.2-296-318.4S184 246.4 152 304 249.6 507.2 448 622.4s392 155.2 424 97.6z' fill='#050D42' /><path d='M512 592c-44.8 0-80-35.2-80-80s35.2-80 80-80 80 35.2 80 80-35.2 80-80 80zM272 312c-27.2 0-48-20.8-48-48s20.8-48 48-48 48 20.8 48 48-20.8 48-48 48zM416 880c-27.2 0-48-20.8-48-48s20.8-48 48-48 48 20.8 48 48-20.8 48-48 48z m448-432c-27.2 0-48-20.8-48-48s20.8-48 48-48 48 20.8 48 48-20.8 48-48 48z' fill='#2F4BFF' /></svg>";

    protected override void OnStart()
    {
        var svgImage = new Image
        {
            Source = new SvgIcon(SVG),
            HorizontalAlignment = HorizontalAlignment.Center,
            VerticalAlignment = VerticalAlignment.Center,
        };

        Chart.AddControl(svgImage);
    }
}
import clr

clr.AddReference("cAlgo.API")

# Import cAlgo API types
from cAlgo.API import *
# Import trading wrapper functions
from robot_wrapper import *

class Test():
    SVG = "<svg width='800px' height='800px' viewBox='0 0 1024 1024' class='icon'  version='1.1' xmlns='http://www.w3.org/2000/svg'><path d='M512 960c-92.8 0-160-200-160-448S419.2 64 512 64s160 200 160 448-67.2 448-160 448z m0-32c65.6 0 128-185.6 128-416S577.6 96 512 96s-128 185.6-128 416 62.4 416 128 416z' fill='#050D42' /><path d='M124.8 736c-48-80 92.8-238.4 307.2-363.2S852.8 208 899.2 288 806.4 526.4 592 651.2 171.2 816 124.8 736z m27.2-16c33.6 57.6 225.6 17.6 424-97.6S905.6 361.6 872 304 646.4 286.4 448 401.6 118.4 662.4 152 720z' fill='#050D42' /><path d='M899.2 736c-46.4 80-254.4 38.4-467.2-84.8S76.8 368 124.8 288s254.4-38.4 467.2 84.8S947.2 656 899.2 736z m-27.2-16c33.6-57.6-97.6-203.2-296-318.4S184 246.4 152 304 249.6 507.2 448 622.4s392 155.2 424 97.6z' fill='#050D42' /><path d='M512 592c-44.8 0-80-35.2-80-80s35.2-80 80-80 80 35.2 80 80-35.2 80-80 80zM272 312c-27.2 0-48-20.8-48-48s20.8-48 48-48 48 20.8 48 48-20.8 48-48 48zM416 880c-27.2 0-48-20.8-48-48s20.8-48 48-48 48 20.8 48 48-20.8 48-48 48z m448-432c-27.2 0-48-20.8-48-48s20.8-48 48-48 48 20.8 48 48-20.8 48-48 48z' fill='#2F4BFF' /></svg>"
    def on_start(self):
        svgImage = Image()
        svgImage.Source = SvgIcon(self.SVG)
        svgImage.HorizontalAlignment = HorizontalAlignment.Center
        svgImage.VerticalAlignment = VerticalAlignment.Center

        api.Chart.AddControl(svgImage)
{
  "AccessRights": "None"
}

Constructors

Name Description
ImageDesktopCLICloud Initializes a new instance of the Image class.

Properties

Name Description
SourceDesktopCLICloudobject Gets or sets the source of the image.
StretchDesktopCLICloudStretch Gets or sets a value that describes how an Image should be stretched to fill the destination rectangle.
StretchDirectionDesktopCLICloudStretchDirection Gets or sets a value that indicates how the image is scaled.

Inherited members

From ControlBase: ResetProperty, UniqueId, Style, Left, Top, Right, Bottom, Width, Height, MinWidth, MinHeight, MaxWidth, MaxHeight, IsEnabled, IsVisible, Opacity, Margin, VerticalAlignment, HorizontalAlignment, Dock, IsHitTestVisible