Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Gosu load_tiles into RMagick images?
- - By Musfuut Date 2010-12-09 16:10 Edited 2010-12-10 02:48
Hi, I've been battling with trying to get something to work for the past couple days.

I'm loading a series of tiles using Gosu::Image::load_tiles, this works perfectly. However I've been trying different combination's of image.to_blob and Magick::Image.from_blob to try to convert the Gosu images into RMagick ones without an ounce of success. I was using TexPlay however I'm trying to generate tiled images exceeding TexPlay size limits so I need to use RMagick for this.

To reiterate I'd like to take a Gosu::Image and convert it to an Magick::Image.

Is this possible? Or do I need to make my own load_tiles method for RMagick and use that to load the image instead of Gosu?

Any help or advice is much appreciated!

Update:
Well I have finally figured out a way to do it. However it requires converting each sub-pixel of data from the blob into an array.

rmagick_img = Magick::Image.constitute(4, 4, "RGBA", @gosu_source_image.to_blob.split(//).map {|x| x[0]})

Any other solutions that I may be missing?

Update 2:
I think I figured out a better way. Anyone can let me know if this is a stupid way to do this, but it works.

width, height = @gosu_image.columns, @gosu_image.rows
rmagick_image = Magick::Image.new(width, height).import_pixels(0, 0, width, height, "RGBA", @gosu_image.to_blob, Magick::CharPixel)

Seems to work like a charm. So now that I'm not pulling my hair out let me just say, thank you for making, supporting, and promoting gosu :) Cheers!
Parent - By jlnr (dev) Date 2010-12-10 12:39
Hello,

I have used this snippet recently:


class Gosu::Image
  def to_rmagick
    this = self
    Magick::Image.from_blob(to_blob) do
      self.format = 'RGBA'
      self.depth = 8
      self.size = "#{this.width}x#{this.height}"
    end.first
  end
end


Good that you asked, now I had an opportunity to post it somewhere :)
Up Topic Gosu / Gosu Exchange / Gosu load_tiles into RMagick images?

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill