GbtPNGFileFormat does actually write the image to a file

40 views
Skip to first unread message

Richard Sargent

unread,
Sep 3, 2025, 5:26:21 PMSep 3
to VAST Community Forum
The following example had me puzzled for a while. I kept ending up with zero length PNG files.

Given a pixmap, such as is produced in #stsSnapshotWindow, the following should have written it to a file. This code is based on StsPowerTools class>>#savePixmapToFile:, but I notice that PNG is not an available snapshot target ... for  probably this  reason.

formatClass := CgPNGFileFormat.
CfsFileDescriptor remove: filename. "Ignore any error; file not found is expected"
pixmap depth: (pixmap depth min: formatClass stsMaxDepth).
image := pixmap getDeviceIndependentImage: pixmap rectangle.
fileDescriptor := CfsFileDescriptor
open: filename
oflag: OCREAT | OTRUNC | OWRONLY.
fileDescriptor isCfsError
ifTrue:
[pixmap freePixmap.
^self gbsMessenger
warn: 'Error occurred saving screen capture: %1'
with: fileDescriptor message].
success := formatClass new
unload: image
intoFileHandle: fileDescriptor
atOffset: 0.
fileDescriptor close.



The solution and explanation is provided by adding a subclass and implementing this method in it. In my case I created  a GbtPNGFileFormat class and successfully used it..

Richard Sargent

unread,
Sep 3, 2025, 5:26:59 PMSep 3
to VAST Community Forum
Dang! There should have been a NOT in the subject.

Mariano Martinez Peck

unread,
Sep 10, 2025, 8:22:41 AM (13 days ago) Sep 10
to va-sma...@googlegroups.com
Hi Richard, 

Thanks for the report. I think you are correct. Could you please verify that the attached fileout does work for you.

Thanks in advance,



--
You received this message because you are subscribed to the Google Groups "VAST Community Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to va-smalltalk...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/va-smalltalk/7883afd3-f5a1-4c10-9717-c081b083e96bn%40googlegroups.com.


--

Mariano Martinez Peck

VAST Lead Consultant

Senior Software Engineer

 mp...@instantiations.com
 @MartinezPeck
 /mariano-martinez-peck
 instantiations.com
TwitterLinkedInVAST Community ForumGitHubYouTubepub.dev
CgPNGEncoder.zip

Richard Sargent

unread,
Sep 10, 2025, 1:16:29 PM (13 days ago) Sep 10
to VAST Community Forum
My test case can be recreated using the following.
StsPowerTools snapshotTarget: CgPNGFileFormat formatName.
EtWindow basicNew stsSnapshotScreen.


This works for every other format, I believe. PNG is excluded, probably because it didn't work.
(See the Options/Snapshot menu item on EtWindows.)

The patch you provided looks good in the sense of capturing more information/detail.
But, the problem is that CgPNGFileFormat doesn't write anything to the file stream.

Seth Berman

unread,
Sep 10, 2025, 1:49:56 PM (13 days ago) Sep 10
to VAST Community Forum
Hi Richard,

I'm not sure how you applied the patch (perhaps manually?), but it seems to work for me.
Notice there are 2 methods in there.  #encode and #encode:

Then to hook it into StsPowerTools, you just create the method below
StsPowerTools class>stsSnapshotTargetPNG

self snapshotTarget: CgPNGFileFormat formatName

---------
then add this section to this existing method.
StsPowerTools class>>stsSnapshotTargetSubMenu
...
add: #stsSnapshotTargetPNG
label: '~PNG File'
enable: [self snapshotTarget ~= CgPNGFileFormat formatName]
toggle: [self snapshotTarget = CgPNGFileFormat formatName]
for: self;
...


- Seth

Richard Sargent

unread,
Sep 10, 2025, 2:08:40 PM (13 days ago) Sep 10
to va-sma...@googlegroups.com
On Wed, Sep 10, 2025 at 10:50 AM 'Seth Berman' via VAST Community Forum <va-sma...@googlegroups.com> wrote:
Hi Richard,

I'm not sure how you applied the patch (perhaps manually?), but it seems to work for me.
Notice there are 2 methods in there.  #encode and #encode:

Yes, I did file it in manually. I don't know how I screwed it up.
I retried it and see the two methods. And, when I try it again, the snapshot works correctly.


You received this message because you are subscribed to a topic in the Google Groups "VAST Community Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/va-smalltalk/vek0yyKErwI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to va-smalltalk...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/va-smalltalk/4aa3e0d0-2e01-497a-9ea0-7bd8acc766ban%40googlegroups.com.

Mariano Martinez Peck

unread,
Sep 10, 2025, 4:12:26 PM (13 days ago) Sep 10
to va-sma...@googlegroups.com
Hi Richard, 

FYI, this fix was tracked in case "74331: CgPNGEncoder >> encode: outputStream should actually write into outputStream" and will be shipped with VAST 15.

Thanks! 

Reply all
Reply to author
Forward
0 new messages