Copy image to clipboard versus actual graphics

While I'm trying to use capture image to clipboard the screen looks empty
Is this related to gfxsetzorder ? I tried to troubleshoot with different zorder but no luck, I looked into different examples here but it is working perfectly so I wonder what am I doing wrong here ?


CellHeight = Param( "Cell Height", 40, 30, 50, 1 );
CellWidth = Param( "Cell Width", 200, 200, 1000, 1 );
transx = Param( "Move Button Pack (X-Axis, bars)", 200, 0, 2000, 10 );
transy = Param( "Move Button Pack (Y-Axis, bars)", 15, 0, 2000, 5 );
trigger = ParamTrigger( "Reset Static Variables", "Click Here" );
slope4=Null;
x0 = 0 + transx;
y0 = 0 + transy;
idSlider = 50;
idslider2=51;
slope3=Null;
row = 1;
timestep = in1Minute;

slider = GuiSlider( idSlider, x0, y0 + ( row - 1 ) * CellHeight, CellWidth, CellHeight, notifyEditChange );
row++;
slider2 = GuiSlider( idSlider+1, x0, y0 + ( row - 1 ) * CellHeight, CellWidth, CellHeight, notifyEditChange );
if( slider == guiNew OR trigger )
{
    GuiSetValue( idSlider, 10 );
    GuiSetRange( idSlider, 1, 240, 1, 10 );
    GuiEnable( idSlider, True );
}
if( slider2 == guiNew OR trigger )
{
    GuiSetValue( idSlider2, 10 );
    GuiSetRange( idSlider2, 1, 240, 1, 10 );
    GuiEnable( idSlider2, True );
}

GfxSetZOrder( 1);
GfxSetCoordsMode( 1 );
SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );


Your post is not clear enough.

What do you mean by graphics?
GUI controls are more MS Windows than AB charts, so unless something has changed, you would need to use windows screenshot as opposed to using AB to include them in export image.

( I think old style was Windows GDI render that was written in-house as QuickGFX but both draw methods actually draw charts ) I could be off a bit but its more or less around this. The GUI controls are elements that are placed "on" the charts in layman sense.

1 Like

@nsm51 the code here has a slider, that is appeared in windows screenshot but not in copy image to clipboard, both images are included in the post
If I'm using windows is there a way to capture the slider using copy image to clipboard

By the way after that I have gfxlineto and other low level drawing that is not captured as well, but I thought to simplify the main issue.

Tomasz had mentioned this somewhere, but it is obvious / general behaviour.
The GUI elements appear on the chart in a different way compared to chart rendering.

I have not tried low-level GFX, but the above is obvious(Gui elements), so instead of export image you need to use windows screenshot.

Will wait for Tomasz, he is the best person to explain if low level GFX can be done among other scenarios.

1 Like

@mmha this was discussed in this thread (see a similar question and the answer from @Tomasz).
As @nsm51 suggested to capure Windows GUI elements you need to use some other approach.

1 Like

Gui controls are NOT part of your chart. GUI controls are separate windows (albeit they are "children") and they live separately on "top" of your chart. GUI controls such as message boxes, checkboxes, etc. they are all part of operating system and rendered by operating system. You can do a screenshot and that would include children because screenshot captures MULTIPLE WINDOWS.
However, chart export feature exports CHART image only, not multiple windows.

Export does not do "screenshots". Export renders your chart into off-screen bitmap and that off-screen bitmap is exported to file.

3 Likes

@Tomasz Extending OPs doubt, low level GFX drawing should appear in export image, right?

He says it didn't work, i haven't tested it.

1 Like

@nsm51 it doesn't work if I have gui controls added, I will try to add one example for same, might be I'm missing something

@Tomasz @beppe Thanks for the details

My workaround using tools js script and below with support of AI to capture the screen after some delay

// --- Configuration ---
var exportPath = "C:\\Program Files\\Amibroker\\export\\";

// --- Main Script ---
var AB, ticker, filename, WshShell, command;

try {
    // Connect to AmiBroker
    AB = new ActiveXObject("Broker.Application");

    // Make sure the AmiBroker window is visible and in the foreground
    // This ensures what you want to capture is visible on screen.
    AB.Visible = true;
    
    // Create a shell object to run external commands
    WshShell = new ActiveXObject("WScript.Shell");

    // IMPORTANT: Activate the AmiBroker main window.
    // This brings it to the front before the screenshot is taken.
    WshShell.AppActivate("AmiBroker");
    WScript.Sleep(500); // Give the OS a moment to switch windows.

    // Get the active ticker and create the full file path
    ticker = AB.ActiveDocument.Name;
    filename = exportPath + ticker + ".png";

    WScript.Echo("Preparing to capture screen to: " + filename);

    // --- The PowerShell Magic ---
    // This command loads the necessary .NET assemblies, captures the primary screen,
    // and saves it to the file specified in 'filename'.
    var psCommand = "Add-Type -AssemblyName System.Windows.Forms; " +
                    "Add-Type -AssemblyName System.Drawing; " +
                    "$screen = [System.Windows.Forms.Screen]::PrimaryScreen.Bounds; " +
                    "$image = New-Object System.Drawing.Bitmap($screen.Width, $screen.Height); " +
                    "$graphic = [System.Drawing.Graphics]::FromImage($image); " +
                    "$graphic.CopyFromScreen($screen.Left+100, $screen.Top+100, 0, 0, $image.Size); " +
                    "$image.Save('" + filename + "', [System.Drawing.Imaging.ImageFormat]::Png);";

    // We build the final command to be executed by the command prompt.
    // 'powershell.exe -Command "..."' is how you run a PowerShell scriptlet.
    command = 'powershell.exe -NoProfile -Command "' + psCommand + '"';

    // WScript.Echo("Executing: " + command); // Uncomment for debugging

    // Run the command. The '0' hides the PowerShell window, 'true' waits for it to finish.
    WshShell.Run(command, 0, true);

    WScript.Echo("Screen capture saved successfully! - Done!");

} catch (e) {
    WScript.Echo("An error occurred: " + e.message);
}

Yes, EVERYTHING except Gui* functions is RENDERED into chart image (including low level graphics) and as such is a part of exported image.

2 Likes

@Tomasz


yes it is working in my troubleshooting example

CellHeight = Param( "Cell Height", 40, 30, 50, 1 );
CellWidth = Param( "Cell Width", 200, 200, 1000, 1 );
transx = Param( "Move Button Pack (X-Axis, bars)", 200, 0, 2000, 10 );
transy = Param( "Move Button Pack (Y-Axis, bars)", 15, 0, 2000, 5 );
trigger = ParamTrigger( "Reset Static Variables", "Click Here" );
slope4=Null;
x0 = 0 + transx;
y0 = 0 + transy;
idSlider = 50;
idslider2=51;
slope3=Null;
row = 1;
timestep = in1Minute;

slider = GuiSlider( idSlider, x0, y0 + ( row - 1 ) * CellHeight, CellWidth, CellHeight, notifyEditChange );
row++;
slider2 = GuiSlider( idSlider+1, x0, y0 + ( row - 1 ) * CellHeight, CellWidth, CellHeight, notifyEditChange );
if( slider == guiNew OR trigger )
{
    GuiSetValue( idSlider, 10 );
    GuiSetRange( idSlider, 1, 240, 1, 10 );
    GuiEnable( idSlider, True );
}
if( slider2 == guiNew OR trigger )
{
    GuiSetValue( idSlider2, 10 );
    GuiSetRange( idSlider2, 1, 240, 1, 10 );
    GuiEnable( idSlider2, True );
}

GfxSetZOrder( 1);
GfxSetCoordsMode( 0 );
SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );

GfxSelectPen(colorAqua,10);
GfxMoveTo(1,1);
GfxLineTo(5000,3000);

I had to look carefully in main formula what is the difference, appreciate your support very much.

Ok here is my issue, I'm just able to replicate by looking closely in the capture I got

CellHeight = Param( "Cell Height", 40, 30, 50, 1 );
CellWidth = Param( "Cell Width", 200, 200, 1000, 1 );
transx = Param( "Move Button Pack (X-Axis, bars)", 200, 0, 2000, 10 );
transy = Param( "Move Button Pack (Y-Axis, bars)", 15, 0, 2000, 5 );
trigger = ParamTrigger( "Reset Static Variables", "Click Here" );
slope4=Null;
x0 = 0 + transx;
y0 = 0 + transy;
idSlider = 50;
idslider2=51;
slope3=Null;
row = 1;


slider = GuiSlider( idSlider, x0, y0 + ( row - 1 ) * CellHeight, CellWidth, CellHeight, notifyEditChange );
row++;
slider2 = GuiSlider( idSlider+1, x0, y0 + ( row - 1 ) * CellHeight, CellWidth, CellHeight, notifyEditChange );
if( slider == guiNew OR trigger )
{
    GuiSetValue( idSlider, 10 );
    GuiSetRange( idSlider, 1, 240, 1, 10 );
    GuiEnable( idSlider, True );
}
if( slider2 == guiNew OR trigger )
{
    GuiSetValue( idSlider2, 10 );
    GuiSetRange( idSlider2, 1, 240, 1, 10 );
    GuiEnable( idSlider2, True );
}

if (GuiGetValue(idslider)>1)
{
GfxSetZOrder( 1);
GfxSetCoordsMode( 0 );
SetChartBkColor( ColorRGB( 0, 0, 0 ) );
SetChartOptions( 0, chartShowArrows | chartShowDates );


GfxSelectPen(colorAqua,10);
GfxMoveTo(1,1);
GfxLineTo(5000,1000);

}


	GfxSetZOrder( 1 );
    GfxSetCoordsMode( 0 );
    GfxSetTextColor( ColorRgb( 0, 255, 255 ) );
    GfxSelectFont( "Arial", 10, 700 );
    GfxSetTextAlign( 0 | 8 );
	GfxTextOut(""+GuiGetValue(idslider),x0+300,y0 + ( 1 - 1 ) * CellHeight);
	GfxTextOut(""+GuiGetValue(idslider2),x0+300,y0 + 2 * CellHeight);
    

The capture is using value different than the value I have from the slider
I.e the slider value is set to 2 as example but while capturing the value is set to 0

Is there any way to preserve the value taken from gui slider while taking screenshot

Actual screen slider values before capture

Copy image to clipboard output

Solved with staticvar


  if (GuiGetValue(idslider)>0)
    StaticVarSet("slider2",GuiGetValue(idslider2),true);
if (GuiGetValue(idslider2)>0)
     StaticVarSet("slider",GuiGetValue(idslider),true);

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.