# Images in FXRuby

**URL:** <https://www.ruby-forum.com/t/images-in-fxruby/82045>\
**Category:** Ruby\
**Created:** [January 17, 2007, 12:52am UTC](https://www.ruby-forum.com/t/images-in-fxruby/82045 "2007-01-17T00:52:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dorelal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3da27b/32.png) [@dorelal](https://www.ruby-forum.com/u/dorelal)\
**Post date:** [January 17, 2007, 12:52am UTC](https://www.ruby-forum.com/t/images-in-fxruby/82045/1 "2007-01-17T00:52:50Z")

</div>

I’m new to FXRuby, and I’m having a problem with displaying images. I’m  
simply trying to display an image in a vertical scroll window, with the  
end result being a program that shows multiple images with vertical  
scrolling. I can get button icons to work just fine. I have tried  
using both FXImageView and FXImageFrame. What am I doing wrong? A  
sample of my code is:

require ‘fox16’  
include Fox  
theApp = FXApp.new

imageFile = File.open(“gm.jpg”, “rb”)  
theMainWindow = FXMainWindow.new(theApp, “Hello”, nil, nil, DECOR\_ALL,  
400, 400)  
firstWindow = FXScrollArea.new(theMainWindow,  
VSCROLLER\_ALWAYS|LAYOUT\_FILL\_X|LAYOUT\_FILL\_Y)  
image = FXJPGIcon.new(theApp, iconFile.read)  
imageView = FXImageView.new(firstWindow, image)

theApp.create  
theMainWindow.show  
theApp.run

---

<div class="post-metadata">

**Author:** ![dorelal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3da27b/32.png) [@dorelal](https://www.ruby-forum.com/u/dorelal)\
**Post date:** [January 17, 2007, 12:55am UTC](https://www.ruby-forum.com/t/images-in-fxruby/82045/2 "2007-01-17T00:55:22Z")

</div>

> image = FXJPGIcon.new(theApp, iconFile.read)

That’s a typo. Should say FXJPGImage.new. But that’s not the problem,  
just a cut and paste error.

---

<div class="post-metadata">

**Author:** ![dorelal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3da27b/32.png) [@dorelal](https://www.ruby-forum.com/u/dorelal)\
**Post date:** [January 17, 2007, 4:22am UTC](https://www.ruby-forum.com/t/images-in-fxruby/82045/3 "2007-01-17T04:22:41Z")

</div>

On 1/16/07, Raj S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m new to FXRuby, and I’m having a problem with displaying images. I’m  
> simply trying to display an image in a vertical scroll window, with the  
> end result being a program that shows multiple images with vertical  
> scrolling. I can get button icons to work just fine. I have tried  
> using both FXImageView and FXImageFrame. What am I doing wrong? A  
> sample of my code is:

Right offhand, I’m not sure, but the problem may be that you’re  
putting the FXImageView (which itself is a subclass of FXScrollArea)  
inside an FXScrollArea. Try making the FXImageView a child of the main  
window (i.e. eliminate the “firstWindow” scroll area in the middle.

Also compare against the imageviewer.rb example program that comes  
with FXRuby to see what you might be doing differently.

Hope this helps,

Lyle

---

<div class="post-metadata">

**Author:** ![dorelal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3da27b/32.png) [@dorelal](https://www.ruby-forum.com/u/dorelal)\
**Post date:** [January 17, 2007, 5:20pm UTC](https://www.ruby-forum.com/t/images-in-fxruby/82045/4 "2007-01-17T17:20:53Z")

</div>

Lyle J. wrote:

> Right offhand, I’m not sure, but the problem may be that you’re  
> putting the FXImageView (which itself is a subclass of FXScrollArea)  
> inside an FXScrollArea. Try making the FXImageView a child of the main  
> window (i.e. eliminate the “firstWindow” scroll area in the middle.
> 
> Also compare against the imageviewer.rb example program that comes  
> with FXRuby to see what you might be doing differently.
> 
> Hope this helps,
> 
> Lyle

Thanks for your help. Just in case anyone searches this in the future,  
I’ll post my working code. The key was loading the image using  
FXFileStream. Also, removing the scroll area produced the same results:

require ‘fox16’  
include Fox

theApp = FXApp.new

theMainWindow = FXMainWindow.new(theApp, “Hello”, nil, nil, DECOR\_ALL,  
400, 400)  
imagebox = FXVerticalFrame.new(theMainWindow,  
FRAME\_SUNKEN|FRAME\_THICK|LAYOUT\_FILL\_X|LAYOUT\_FILL\_Y)  
imageView = FXImageView.new(imagebox, nil, nil, 0,  
VSCROLLER\_ALWAYS|LAYOUT\_FILL\_X|LAYOUT\_FILL\_Y)  
image = FXJPGImage.new(theApp, nil)  
FXFileStream.open(“gm.jpg”, FXStreamLoad) {|stream|  
image.loadPixels(stream)}  
image.create  
imageView.image = image

theApp.create  
theMainWindow.show  
theApp.run
