MakeScreenshot for dynamically created control












3















I need to draw dynammically created control to bitmap.
But it does not work. It draw nothing



procedure TForm2.Button1Click(Sender: TObject);
var
cb: TCheckBox;
BMP: TBitmap;
begin
BMP:= nil;

cb:= TCheckBox.Create(nil);
try
cb.IsChecked:= true;
cb.Repaint;
BMP:= cb.MakeScreenshot;
BMP.SaveToFile('C:bmp.bmp');
finally
FreeAndNil(cb);
FreeAndNil(BMP);
end;
end;


I have tried also directly PaintTo - but the same effect.
I have tried also setting parent but this is still not enought.
If i do same for control placed by hand on the form it is working, but dynnamically created not.



How to do this. This control should not be visible anywhere i need to paint it only and free it.










share|improve this question

























  • I am really interested why someone vote against this question? It is not clear? It do not show my effort? Or what?

    – Livius
    Nov 14 '18 at 12:47











  • Have you tried adding a parent to your checkbox?

    – fpiette
    Nov 14 '18 at 12:53











  • My suggestion is that your TCheckBox should be visible before making screenshot. I'm doubting that control stores its visual appearance inside of itself on internal bitmap and ready to deliver it on demand. And also wrap bitmap creating in separate try...finally.

    – Dima
    Nov 14 '18 at 13:29













  • @Dima TCheckBox is visible by default when creating new. No need for an additional try/finally around the BMP - it is initialized to nil, so the existing Free will take care of the generated object in MakeScreenShot if it is successfully created but subsequent calls in the try fail.

    – J...
    Nov 14 '18 at 13:56
















3















I need to draw dynammically created control to bitmap.
But it does not work. It draw nothing



procedure TForm2.Button1Click(Sender: TObject);
var
cb: TCheckBox;
BMP: TBitmap;
begin
BMP:= nil;

cb:= TCheckBox.Create(nil);
try
cb.IsChecked:= true;
cb.Repaint;
BMP:= cb.MakeScreenshot;
BMP.SaveToFile('C:bmp.bmp');
finally
FreeAndNil(cb);
FreeAndNil(BMP);
end;
end;


I have tried also directly PaintTo - but the same effect.
I have tried also setting parent but this is still not enought.
If i do same for control placed by hand on the form it is working, but dynnamically created not.



How to do this. This control should not be visible anywhere i need to paint it only and free it.










share|improve this question

























  • I am really interested why someone vote against this question? It is not clear? It do not show my effort? Or what?

    – Livius
    Nov 14 '18 at 12:47











  • Have you tried adding a parent to your checkbox?

    – fpiette
    Nov 14 '18 at 12:53











  • My suggestion is that your TCheckBox should be visible before making screenshot. I'm doubting that control stores its visual appearance inside of itself on internal bitmap and ready to deliver it on demand. And also wrap bitmap creating in separate try...finally.

    – Dima
    Nov 14 '18 at 13:29













  • @Dima TCheckBox is visible by default when creating new. No need for an additional try/finally around the BMP - it is initialized to nil, so the existing Free will take care of the generated object in MakeScreenShot if it is successfully created but subsequent calls in the try fail.

    – J...
    Nov 14 '18 at 13:56














3












3








3








I need to draw dynammically created control to bitmap.
But it does not work. It draw nothing



procedure TForm2.Button1Click(Sender: TObject);
var
cb: TCheckBox;
BMP: TBitmap;
begin
BMP:= nil;

cb:= TCheckBox.Create(nil);
try
cb.IsChecked:= true;
cb.Repaint;
BMP:= cb.MakeScreenshot;
BMP.SaveToFile('C:bmp.bmp');
finally
FreeAndNil(cb);
FreeAndNil(BMP);
end;
end;


I have tried also directly PaintTo - but the same effect.
I have tried also setting parent but this is still not enought.
If i do same for control placed by hand on the form it is working, but dynnamically created not.



How to do this. This control should not be visible anywhere i need to paint it only and free it.










share|improve this question
















I need to draw dynammically created control to bitmap.
But it does not work. It draw nothing



procedure TForm2.Button1Click(Sender: TObject);
var
cb: TCheckBox;
BMP: TBitmap;
begin
BMP:= nil;

cb:= TCheckBox.Create(nil);
try
cb.IsChecked:= true;
cb.Repaint;
BMP:= cb.MakeScreenshot;
BMP.SaveToFile('C:bmp.bmp');
finally
FreeAndNil(cb);
FreeAndNil(BMP);
end;
end;


I have tried also directly PaintTo - but the same effect.
I have tried also setting parent but this is still not enought.
If i do same for control placed by hand on the form it is working, but dynnamically created not.



How to do this. This control should not be visible anywhere i need to paint it only and free it.







delphi firemonkey delphi-10.2-tokyo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 11:59







Livius

















asked Nov 14 '18 at 11:52









LiviusLivius

706317




706317













  • I am really interested why someone vote against this question? It is not clear? It do not show my effort? Or what?

    – Livius
    Nov 14 '18 at 12:47











  • Have you tried adding a parent to your checkbox?

    – fpiette
    Nov 14 '18 at 12:53











  • My suggestion is that your TCheckBox should be visible before making screenshot. I'm doubting that control stores its visual appearance inside of itself on internal bitmap and ready to deliver it on demand. And also wrap bitmap creating in separate try...finally.

    – Dima
    Nov 14 '18 at 13:29













  • @Dima TCheckBox is visible by default when creating new. No need for an additional try/finally around the BMP - it is initialized to nil, so the existing Free will take care of the generated object in MakeScreenShot if it is successfully created but subsequent calls in the try fail.

    – J...
    Nov 14 '18 at 13:56



















  • I am really interested why someone vote against this question? It is not clear? It do not show my effort? Or what?

    – Livius
    Nov 14 '18 at 12:47











  • Have you tried adding a parent to your checkbox?

    – fpiette
    Nov 14 '18 at 12:53











  • My suggestion is that your TCheckBox should be visible before making screenshot. I'm doubting that control stores its visual appearance inside of itself on internal bitmap and ready to deliver it on demand. And also wrap bitmap creating in separate try...finally.

    – Dima
    Nov 14 '18 at 13:29













  • @Dima TCheckBox is visible by default when creating new. No need for an additional try/finally around the BMP - it is initialized to nil, so the existing Free will take care of the generated object in MakeScreenShot if it is successfully created but subsequent calls in the try fail.

    – J...
    Nov 14 '18 at 13:56

















I am really interested why someone vote against this question? It is not clear? It do not show my effort? Or what?

– Livius
Nov 14 '18 at 12:47





I am really interested why someone vote against this question? It is not clear? It do not show my effort? Or what?

– Livius
Nov 14 '18 at 12:47













Have you tried adding a parent to your checkbox?

– fpiette
Nov 14 '18 at 12:53





Have you tried adding a parent to your checkbox?

– fpiette
Nov 14 '18 at 12:53













My suggestion is that your TCheckBox should be visible before making screenshot. I'm doubting that control stores its visual appearance inside of itself on internal bitmap and ready to deliver it on demand. And also wrap bitmap creating in separate try...finally.

– Dima
Nov 14 '18 at 13:29







My suggestion is that your TCheckBox should be visible before making screenshot. I'm doubting that control stores its visual appearance inside of itself on internal bitmap and ready to deliver it on demand. And also wrap bitmap creating in separate try...finally.

– Dima
Nov 14 '18 at 13:29















@Dima TCheckBox is visible by default when creating new. No need for an additional try/finally around the BMP - it is initialized to nil, so the existing Free will take care of the generated object in MakeScreenShot if it is successfully created but subsequent calls in the try fail.

– J...
Nov 14 '18 at 13:56





@Dima TCheckBox is visible by default when creating new. No need for an additional try/finally around the BMP - it is initialized to nil, so the existing Free will take care of the generated object in MakeScreenShot if it is successfully created but subsequent calls in the try fail.

– J...
Nov 14 '18 at 13:56












1 Answer
1






active

oldest

votes


















4














Two issues. First, you do need the control to be parented for it to be paintable.



Second, you're saving as a BMP which does not support the transparency used in FMX to generate the screenshot (and is platform specific besides). Save it as a PNG instead.



procedure TForm1.FormCreate(Sender: TObject);
var
cb: TCheckBox;
BMP: TBitmap;
begin
BMP:= nil;
cb:= TCheckBox.Create(nil);
try
cb.Parent := self;
cb.Text := 'testing';
cb.IsChecked:= true;
bmp := cb.MakeScreenshot;
BMP.SaveToFile('C:bmp.png');
finally
cb.Free;
BMP.Free;
end;
end;





share|improve this answer



















  • 3





    Interesting detail though, if you omit the Text assignment, the whole cb image is totally black. If you assign just a space or any other text, it shows up as expected.

    – Tom Brunberg
    Nov 14 '18 at 14:03











  • Yes, the problem was TEXT. If ommited, checkbox was not draw at all. Thank you.

    – Livius
    Nov 14 '18 at 14:31











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299629%2fmakescreenshot-for-dynamically-created-control%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4














Two issues. First, you do need the control to be parented for it to be paintable.



Second, you're saving as a BMP which does not support the transparency used in FMX to generate the screenshot (and is platform specific besides). Save it as a PNG instead.



procedure TForm1.FormCreate(Sender: TObject);
var
cb: TCheckBox;
BMP: TBitmap;
begin
BMP:= nil;
cb:= TCheckBox.Create(nil);
try
cb.Parent := self;
cb.Text := 'testing';
cb.IsChecked:= true;
bmp := cb.MakeScreenshot;
BMP.SaveToFile('C:bmp.png');
finally
cb.Free;
BMP.Free;
end;
end;





share|improve this answer



















  • 3





    Interesting detail though, if you omit the Text assignment, the whole cb image is totally black. If you assign just a space or any other text, it shows up as expected.

    – Tom Brunberg
    Nov 14 '18 at 14:03











  • Yes, the problem was TEXT. If ommited, checkbox was not draw at all. Thank you.

    – Livius
    Nov 14 '18 at 14:31
















4














Two issues. First, you do need the control to be parented for it to be paintable.



Second, you're saving as a BMP which does not support the transparency used in FMX to generate the screenshot (and is platform specific besides). Save it as a PNG instead.



procedure TForm1.FormCreate(Sender: TObject);
var
cb: TCheckBox;
BMP: TBitmap;
begin
BMP:= nil;
cb:= TCheckBox.Create(nil);
try
cb.Parent := self;
cb.Text := 'testing';
cb.IsChecked:= true;
bmp := cb.MakeScreenshot;
BMP.SaveToFile('C:bmp.png');
finally
cb.Free;
BMP.Free;
end;
end;





share|improve this answer



















  • 3





    Interesting detail though, if you omit the Text assignment, the whole cb image is totally black. If you assign just a space or any other text, it shows up as expected.

    – Tom Brunberg
    Nov 14 '18 at 14:03











  • Yes, the problem was TEXT. If ommited, checkbox was not draw at all. Thank you.

    – Livius
    Nov 14 '18 at 14:31














4












4








4







Two issues. First, you do need the control to be parented for it to be paintable.



Second, you're saving as a BMP which does not support the transparency used in FMX to generate the screenshot (and is platform specific besides). Save it as a PNG instead.



procedure TForm1.FormCreate(Sender: TObject);
var
cb: TCheckBox;
BMP: TBitmap;
begin
BMP:= nil;
cb:= TCheckBox.Create(nil);
try
cb.Parent := self;
cb.Text := 'testing';
cb.IsChecked:= true;
bmp := cb.MakeScreenshot;
BMP.SaveToFile('C:bmp.png');
finally
cb.Free;
BMP.Free;
end;
end;





share|improve this answer













Two issues. First, you do need the control to be parented for it to be paintable.



Second, you're saving as a BMP which does not support the transparency used in FMX to generate the screenshot (and is platform specific besides). Save it as a PNG instead.



procedure TForm1.FormCreate(Sender: TObject);
var
cb: TCheckBox;
BMP: TBitmap;
begin
BMP:= nil;
cb:= TCheckBox.Create(nil);
try
cb.Parent := self;
cb.Text := 'testing';
cb.IsChecked:= true;
bmp := cb.MakeScreenshot;
BMP.SaveToFile('C:bmp.png');
finally
cb.Free;
BMP.Free;
end;
end;






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 13:46









J...J...

23.8k345102




23.8k345102








  • 3





    Interesting detail though, if you omit the Text assignment, the whole cb image is totally black. If you assign just a space or any other text, it shows up as expected.

    – Tom Brunberg
    Nov 14 '18 at 14:03











  • Yes, the problem was TEXT. If ommited, checkbox was not draw at all. Thank you.

    – Livius
    Nov 14 '18 at 14:31














  • 3





    Interesting detail though, if you omit the Text assignment, the whole cb image is totally black. If you assign just a space or any other text, it shows up as expected.

    – Tom Brunberg
    Nov 14 '18 at 14:03











  • Yes, the problem was TEXT. If ommited, checkbox was not draw at all. Thank you.

    – Livius
    Nov 14 '18 at 14:31








3




3





Interesting detail though, if you omit the Text assignment, the whole cb image is totally black. If you assign just a space or any other text, it shows up as expected.

– Tom Brunberg
Nov 14 '18 at 14:03





Interesting detail though, if you omit the Text assignment, the whole cb image is totally black. If you assign just a space or any other text, it shows up as expected.

– Tom Brunberg
Nov 14 '18 at 14:03













Yes, the problem was TEXT. If ommited, checkbox was not draw at all. Thank you.

– Livius
Nov 14 '18 at 14:31





Yes, the problem was TEXT. If ommited, checkbox was not draw at all. Thank you.

– Livius
Nov 14 '18 at 14:31


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53299629%2fmakescreenshot-for-dynamically-created-control%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python