about jpge image resize/crop/scale

View: New views
1 Messages — Rating Filter:   Alert me  

about jpge image resize/crop/scale

by imoldcat :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
 
I wrote my first fxruby code today by following progmatic fxruby book example. :)
 
The thing I want to implement is something like "windows image and fax viewer".
The problem was when trying to deal with the maximize and minimize event, I called FXJPGImage's crop/resize/scale and the image had not been resized, but the FXImageFrame showed black. I thought maybe the FXMainWindow or FXImageFrame need to be refreshed. However, I could not find related method.
 
How to resize a jpeg file by using FXJPGImage and FXImageFrame?
 
Thanks a lot in advance ...
 
Here's the code, which depends on exif lib, 'exifr' http://exifr.rubyforge.org/  .
The code read a jpeg image path from command line and show the jpeg in a FXImageFrame with original width and height. Then I want to implement the resize function, at least maximize and minimize button. The SEL_MAXIMIZE event, I can not get it correctly either by setting notify to true or false. So I used SIG_CONFIG. When click the maximize button, the window will become all black ......
 
 
require 'fox16'
require "exifr"
include Fox
# for maximize the picture, a possible solution is to use the rmagick
def showImage(pic_path)
  FXApp.new do |app|
    pbox = PictureBook.new(app, pic_path)
    app.create
    app.run
    app.stop
  end
end
class Photo
  attr_reader :path
 
  def initialize(path)
    @path  = path
  end
end
class PhotoView < FXImageFrame
  def initialize(p, photo)
    super(p, nil)
    load_image(photo.path)
  end
  def load_image(path)
    File.open(path, "rb") do |io|
      self.image = FXJPGImage.new(app, io.read)
    end
  end
  def resize(w, h)
    super(w, h)
    self.image.scale(w, h)
    # self.image.crop(0, 0, w, h)
    # self.image.resize(w, h)
  end
end
class PictureBook < FXMainWindow 
  def initialize(app, pic_path)
    img = EXIFR::JPEG.new(pic_path)
    img_h = img.to_hash
    # to maximize the picture at the beginning
    # show(PLACEMENT_MAXIMIZED)
    super(app, "Picture", :width => img_h[:width], :height => img_h[:height])
    photo = Photo.new(pic_path)
    @photo_view = PhotoView.new(self, photo)
   
    handle_resize
  end
 
  def handle_resize
    connect(SEL_CONFIGURE) do |sender, sel, event|
      if isMaximized
        @photo_view.resize(2048, 1536)
      end
    end
  end
  def create
    super
    show(PLACEMENT_SCREEN)
  end
end
if __FILE__ == $0
  if (ARGV.size > 0)
    showImage(ARGV[0])
  end
end
 

_______________________________________________
fxruby-users mailing list
fxruby-users@...
http://rubyforge.org/mailman/listinfo/fxruby-users