FXRuby Image Scaling question

P

Patrick Hurley

I have a screen with a logo on it, I would like the logo to scale with
screen size. I have tried more than a couple variations on:

# Construct an image
@logo =3D FXPNGImage.new(getApp(), File.open("logo.png", "rb").read,
IMAGE_KEEP)

# Prep an image Frame
image =3D FXImageFrame.new(self, @logo, LAYOUT_FILL_X | LAYOUT_FILL_Y)
image.backColor =3D FXColor::Blue

image.connect(SEL_CONFIGURE) do |sender, sel, evt|
if image.width > 100 && image.height > 100
@logo.scale(image.width, image.height)
end
end

This works, but the image "degrades" from all the scaling. How would I
go about keeping the original image? Any sort of "dup" on the FXImage
results in an exception (at least for me).

Thanks in advance
pth
 
P

Patrick Hurley

I have a screen with a logo on it, I would like the logo to scale with
screen size. I have tried more than a couple variations on:

# Construct an image
@logo =3D FXPNGImage.new(getApp(), File.open("logo.png", "rb").read,
IMAGE_KEEP)

# Prep an image Frame
image =3D FXImageFrame.new(self, @logo, LAYOUT_FILL_X | LAYOUT_FILL_Y= )
image.backColor =3D FXColor::Blue

image.connect(SEL_CONFIGURE) do |sender, sel, evt|
if image.width > 100 && image.height > 100
@logo.scale(image.width, image.height)
end
end

This works, but the image "degrades" from all the scaling. How would I
go about keeping the original image? Any sort of "dup" on the FXImage
results in an exception (at least for me).

Thanks in advance
pth

Ok I am still very interested if there is a better solution, but this
works for me:

# Construct an image
@logo =3D FXPNGImage.new(getApp(), File.open("logo.png", "rb").read,
IMAGE_KEEP)
stream =3D FXMemoryStream.open(FXStreamSave,nil)
@logo.savePixels(stream)
puts stream
@buffer =3D stream.takeBuffer
stream.close
p @buffer

# Prep an image Frame
image =3D FXImageFrame.new(self, @logo, LAYOUT_FILL_X | LAYOUT_FILL_Y)
image.backColor =3D FXColor::Blue

image.connect(SEL_CONFIGURE) do |sender, sel, evt|
if image.width > 100 && image.height > 100
stream =3D FXMemoryStream.open(FXStreamLoad, @buffer)
@logo.loadPixels(stream)
@logo.scale(image.width, image.height)
stream.close
end
end
end
 
P

Patrick Hurley

Ok I am still very interested if there is a better solution, but this
works for me:

# Construct an image
@logo =3D FXPNGImage.new(getApp(), File.open("logo.png", "rb").read,
IMAGE_KEEP)
stream =3D FXMemoryStream.open(FXStreamSave,nil)
@logo.savePixels(stream)
puts stream
@buffer =3D stream.takeBuffer
stream.close
p @buffer

# Prep an image Frame
image =3D FXImageFrame.new(self, @logo, LAYOUT_FILL_X | LAYOUT_FILL_Y= )
image.backColor =3D FXColor::Blue

image.connect(SEL_CONFIGURE) do |sender, sel, evt|
if image.width > 100 && image.height > 100
stream =3D FXMemoryStream.open(FXStreamLoad, @buffer)
@logo.loadPixels(stream)
@logo.scale(image.width, image.height)
stream.close
end
end
end

At the risk of talking to myself too much. Here is the cleaned up solution:

class FXScaledImageFrame < FXImageFrame
def initialize(parent, img, opts =3D
FRAME_SUNKEN|FRAME_THICK,x=3D0,y=3D0,w=3D0,h=3D0,pl=3D0,pr=3D0,pt=3D0,pb=3D=
0)
@img =3D img
FXMemoryStream.open(FXStreamSave, nil) do |stream|
@img.savePixels(stream)
@buffer =3D stream.takeBuffer
end

super

self.connect(SEL_CONFIGURE) do |sender, sel, evt|
if width > 1 and height > 1
FXMemoryStream.open(FXStreamLoad, @buffer) do |stream|
@img.loadPixels(stream)
end
@img.scale(width, height)
end
end

yield self if block_given?
end
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top