MakeScreenshot for dynamically created control
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
add a comment |
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
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 yourTCheckBox
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 separatetry...finally
.
– Dima
Nov 14 '18 at 13:29
@DimaTCheckBox
is visible by default when creating new. No need for an additionaltry/finally
around the BMP - it is initialized tonil
, so the existingFree
will take care of the generated object inMakeScreenShot
if it is successfully created but subsequent calls in thetry
fail.
– J...
Nov 14 '18 at 13:56
add a comment |
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
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
delphi firemonkey delphi-10.2-tokyo
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 yourTCheckBox
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 separatetry...finally
.
– Dima
Nov 14 '18 at 13:29
@DimaTCheckBox
is visible by default when creating new. No need for an additionaltry/finally
around the BMP - it is initialized tonil
, so the existingFree
will take care of the generated object inMakeScreenShot
if it is successfully created but subsequent calls in thetry
fail.
– J...
Nov 14 '18 at 13:56
add a comment |
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 yourTCheckBox
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 separatetry...finally
.
– Dima
Nov 14 '18 at 13:29
@DimaTCheckBox
is visible by default when creating new. No need for an additionaltry/finally
around the BMP - it is initialized tonil
, so the existingFree
will take care of the generated object inMakeScreenShot
if it is successfully created but subsequent calls in thetry
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
add a comment |
1 Answer
1
active
oldest
votes
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;
3
Interesting detail though, if you omit theText
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 wasTEXT
. If ommited, checkbox was not draw at all. Thank you.
– Livius
Nov 14 '18 at 14:31
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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;
3
Interesting detail though, if you omit theText
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 wasTEXT
. If ommited, checkbox was not draw at all. Thank you.
– Livius
Nov 14 '18 at 14:31
add a comment |
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;
3
Interesting detail though, if you omit theText
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 wasTEXT
. If ommited, checkbox was not draw at all. Thank you.
– Livius
Nov 14 '18 at 14:31
add a comment |
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;
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;
answered Nov 14 '18 at 13:46
J...J...
23.8k345102
23.8k345102
3
Interesting detail though, if you omit theText
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 wasTEXT
. If ommited, checkbox was not draw at all. Thank you.
– Livius
Nov 14 '18 at 14:31
add a comment |
3
Interesting detail though, if you omit theText
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 wasTEXT
. 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 separatetry...finally
.– Dima
Nov 14 '18 at 13:29
@Dima
TCheckBox
is visible by default when creating new. No need for an additionaltry/finally
around the BMP - it is initialized tonil
, so the existingFree
will take care of the generated object inMakeScreenShot
if it is successfully created but subsequent calls in thetry
fail.– J...
Nov 14 '18 at 13:56