Giter Site home page Giter Site logo

bmp-ruby's Introduction

bmp-ruby

Introduction

bmp-ruby is a lightweight library for reading and writing Windows BMP files. bmp-ruby is written in Ruby (Ruby 1.9 or later).

Supported reading/writing formats:

  • RGB 8,8,8 (no compression)

Bitmap files with image data in bottom-to-top order (common) is supported.

RubyでBMP画像(Windowsビットマップ)を扱うためのライブラリです。

現状では、無圧縮の24bitカラー(1677万色)にのみ対応しています。

このライブラリを使ってできること

  • 新しいビットマップ画像を生成する
  • 既存のBMPファイルを読み込む
  • ビットマップ画像全体を一色で塗りつぶし
  • ビットマップ画像のピクセル単位の色の読み込み/書き換え
  • ビットマップ画像の切り抜き(クリッピング)
  • ひとつのビットマップ画像の上に別のビットマップ画像を貼り付ける
  • BMPファイルとして書き出す

新しいビットマップ画像を生成する

require './bmp.rb'

new_image = BitMap.new(width, height, dpi)

※ dpiのパラメータは省略できます(その場合、96dpiとなる)。

既存のBMPファイルを読み込む

loaded_image = BitMap.read(filename)

ビットマップ画像全体を一色で塗りつぶし

image.clear(red, green, blue)

※ red, green, blue各色は 0~255 の整数

ビットマップ画像のピクセル単位の色の読み込み

color = image.pget(x, y)
red   = color[0]
green = color[1]
blue  = color[2]

※ x, y は整数であること
※ 座標系は画像の左上を原点として、右方向、下方向が正になります。

ビットマップ画像のピクセル単位の色の書き換え

image.pset(x, y, red, green, blue)

※ x, y は整数であること
※ red, green, blue各色は 0~255 の整数

ビットマップ画像の切り抜き(クリッピング)

clipped_image = original_image.clip(x1, y1, x2, y2)

※ x1 <= x2, y1 <= y2 にしてください

ひとつのビットマップ画像の上に別のビットマップ画像を貼り付ける

base_image.paste(image, x0, y0)

※ x0, y0 は、image の左上を base_image のどこに置くかの指定です。
※ x0, y0 は整数であること

BMPファイルとして書き出す

image.write(filename)

bmp-ruby's People

Contributors

yoyoichi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.