[fxruby-users] Snapshot of a widget
Riccardo Giannitrapani
riccardo at fisica.uniud.it
Fri Aug 27 04:22:20 EDT 2004
Dear all
I have a problem that is probably really stupid, but that I cannot solve
at the moment and I'm wondering if
someone has an idea of what's going wrong .. mainly inspired by the
cookbook snippet of Lyle
http://www.fifthplanet.net/cgi-bin/wiki.pl?Cookbook/Making_A_Snapshot_Of_A_Widget
I've done a small function in my code to take snapshots of widgets from
inside my application in Ruby ..
here it is the code
######################################################################
# Create a snapshot of the drawable, where drawable is
# any FXDrawable subclass
def makeSnapshot(filename, drawable)
completeName = File.basename(filename).match(/(.*)\.(.*)/)
extension = completeName[2] unless completeName == nil
case extension
when "gif"
snapshot = FXGIFImage.new($FredMW.getApp(), nil, 0,
drawable.getWidth(), drawable.getHeight())
when "bmp"
snapshot = FXBMPImage.new($FredMW.getApp(), nil, 0,
drawable.getWidth(), drawable.getHeight())
when "jpg"
snapshot = FXJPGImage.new($FredMW.getApp(), nil, 0,
drawable.getWidth(), drawable.getHeight())
when "png"
snapshot = FXPNGImage.new($FredMW.getApp(), nil, 0,
drawable.getWidth(), drawable.getHeight())
else
FXMessageBox.error(self, MBOX_OK, "Error on file format", "Please, use
a file extension among (gif, bmp, jpg, png).")
return
end
snapshot.create()
dc = FXDCWindow.new(snapshot)
dc.drawArea(drawable, 0, 0, drawable.getWidth(), drawable.getHeight(),
0, 0)
dc.end()
snapshot.restore()
FXFileStream.open(filename, FXStreamSave){|stream|
snapshot.savePixels(stream)
}
end
######################################################################
The problem is that this function works great on Windows, without any
problem .. on Linux instead it produces broken images (
I cannot open the PNG with Gimp since it says something about a PNG broken
.. the BMP format can be open but there is trash in the image, not the
widget) .. any idea of what can be different between windows and linux on
that particular function?
I'm using Ruby 1.8.1 and FXRuby 1.0.25
Thanks for the help, Riccardo :)
--
Riccardo Giannitrapani
Dipartimento di Fisica - Room L1-14-BE
Universita` di Udine - Via delle Scienze, 206 Udine (Italy)
Tel (Office): +39-0432-558209
Home Page: http://www.fisica.uniud.it/~riccardo
ICQ# 86590904
More information about the fxruby-users
mailing list