设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1269|回复: 0
打印 上一主题 下一主题

[谜之脚本] 多个IconSet合并成一个

[复制链接]

只有笨蛋才会看到

梦石
1
星屑
21005
在线时间
9337 小时
注册时间
2012-6-19
帖子
7107

开拓者短篇九导演组冠军

跳转到指定楼层
1
发表于 2015-1-10 02:14:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
插入脚本,图片扔到游戏目录下的ICO文件夹中,文件名用英文或者数字,运行游戏,之后游戏目录下会生成合并好的文件
  1. # PNG 保存 (CACAO http://cacaosoft.web.fc2.com/)
  2. class Bitmap
  3.   def save_png(filename, alpha = false)
  4.     sgnt = "\x89PNG\r\n\x1a\n"
  5.     ihdr = _chunk('IHDR', [width,height,8,(alpha ? 6 : 2),0,0,0].pack('N2C5'))
  6.     data = []
  7.     height.times do |y|
  8.       data << 0
  9.       width.times do |x|
  10.         color = self.get_pixel(x, y)
  11.         data << color.red << color.green << color.blue
  12.         data << color.alpha if alpha
  13.       end
  14.     end
  15.     idat = _chunk('IDAT', Zlib::Deflate.deflate(data.pack('C*')))
  16.     iend = _chunk('IEND', "")
  17.     File.open(filename, 'wb') do |file|
  18.       file.write(sgnt)
  19.       file.write(ihdr)
  20.       file.write(idat)
  21.       file.write(iend)
  22.     end
  23.   end
  24. private
  25.   def _chunk(name, data)
  26.     return [data.size, name, data, Zlib.crc32(name + data)].pack('NA4A*N')
  27.   end
  28. end
  29. def conv_2_24(num)
  30.   loop do
  31.     break if num % 24 == 0
  32.     num += 1
  33.   end
  34.   return num
  35. end
  36. path = "ICO"
  37. bitmap_list = []
  38. Dir.foreach(path) do |file|
  39.   filename = path + "/" + file  
  40.   if FileTest.file?(filename)
  41.     bitmap_list << Bitmap.new(filename)
  42.   end
  43. end
  44. height = 0
  45. bitmap_list.each {|bitmap| height += bitmap.height }
  46. height = conv_2_24(height)
  47. final_file = Bitmap.new(384,height)
  48. pos = 0
  49. bitmap_list.each do |bitmap|
  50.   pos = conv_2_24(pos)  
  51.   rect = Rect.new(0,0,bitmap.width,bitmap.height)
  52.   final_file.blt(0, pos, bitmap, rect)
  53.   pos += bitmap.height
  54. end
  55. final_file.save_png("IconSet.png", true)
  56. exit
复制代码
拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-7 18:30

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表