# WxRuby: Opening and Displaying PNG images on a window

**URL:** <https://www.ruby-forum.com/t/wxruby-opening-and-displaying-png-images-on-a-window/99815>\
**Category:** Ruby\
**Created:** [July 25, 2006, 6:42pm UTC](https://www.ruby-forum.com/t/wxruby-opening-and-displaying-png-images-on-a-window/99815 "2006-07-25T18:42:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kpeng1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/919ad9/32.png) [@kpeng1](https://www.ruby-forum.com/u/kpeng1)\
**Post date:** [July 25, 2006, 6:42pm UTC](https://www.ruby-forum.com/t/wxruby-opening-and-displaying-png-images-on-a-window/99815/1 "2006-07-25T18:42:04Z")

</div>

Hello,

I am still pretty new to wxwidgets and I am trying to learn as fast as  
possible.

Currently I am using wxruby and I want to build an application that  
would display all png images that are in its current directory as  
thumbnails and once a user clicks on one of these thumbnails another  
application would launch displaying a better resolution or larger  
version of the thumbnail image.

I have been looking at the Image, ImageList and PNGHandler classes, but  
I cannot seem to get anything to work. I cannot even declare a handler.

At this point I just want png thumbnails to display in a window.

Any help or hints would be appreciated.

---

<div class="post-metadata">

**Author:** ![kpeng1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/919ad9/32.png) [@kpeng1](https://www.ruby-forum.com/u/kpeng1)\
**Post date:** [July 25, 2006, 8:05pm UTC](https://www.ruby-forum.com/t/wxruby-opening-and-displaying-png-images-on-a-window/99815/2 "2006-07-25T20:05:54Z")

</div>

kpeng1 wrote:

> Hello,
> 
> I am still pretty new to wxwidgets and I am trying to learn as fast as  
> possible.

A good place to start is among the samples that come with wxruby and  
wxruby2. These give short illustrations of how to use a lot of the  
classes.

> I have been looking at the Image, ImageList and PNGHandler classes, but  
> I cannot seem to get anything to work. I cannot even declare a handler.

There is a sample that shows how to load a PNG image. Something like:

class MyFrame \< Wx::Frame  
def initialize(title)  
super(nil, -1, title)  
evt\_paint { on\_paint }  
image = Wx::Image.new(‘paperclip.png’) # load the image from the  
file  
@bitmap = Wx::Bitmap.new(image) # convert it to a bitmap, ready for  
drawing with  
end

def on\_paint  
paint do | dc |  
dc.clear  
dc.draw\_bitmap(@bitmap, 0, 0, false) # draw the  
end  
end  
end

> At this point I just want png thumbnails to display in a window.

Wx::Image seems to have ‘resize’ and ‘rescale’ methods among others,  
though I haven’t ever tried these. All the methods that are  
(potentially) available can be seen at  
[http://www.wxwindows.org/manuals/2.6.3/wx\_wximage.html#wximage](http://www.wxwindows.org/manuals/2.6.3/wx_wximage.html#wximage) .

You could also use another package to create thumbnails, eg RMagick.

> Any help or hints would be appreciated.

Another source of help is the wxruby mailing list

cheers  
alex
