-
Notifications
You must be signed in to change notification settings - Fork 1
画像編集
Reputeless edited this page Mar 14, 2017
·
4 revisions
Image
クラスは画像データを扱います。Texture
と異なり、画像を画面に描くことはできませんが、プログラムでピクセルの色を調べたり変更したりできます。
Image
の内容を画面に描くには、Image
から Texture
を作成します。

# include <Siv3D.hpp>
void Main()
{
const Image image(L"Example/Windmill.png");
if (!image)
{
return;
}
Println(L"画像の幅: ", image.width);
Println(L"画像の高さ: ", image.height);
WaitKey();
}
# include <Siv3D.hpp>
void Main()
{
const Image image(L"Example/Windmill.png");
// PNG
image.save(L"images/Windmill.png");
// JPEG
image.save(L"images/Windmill.jpg");
// BMP
image.save(L"images/Windmill.bmp");
// GIF
image.save(L"images/Windmill.gif");
// TIFF
image.save(L"images/Windmill.tif");
// JPEG 2000
image.save(L"images/Windmill.jp2");
// DDS
image.save(L"images/Windmill.dds");
// WebP
image.save(L"images/Windmill.webp");
// TGA
image.save(L"images/Windmill.tga");
// PPM
image.save(L"images/Windmill.ppm");
}

# include <Siv3D.hpp>
void Main()
{
const Image image(L"Example/Windmill.png");
const Texture texture(image);
while (System::Update())
{
texture.draw();
}
}

# include <Siv3D.hpp>
void Main()
{
// 幅 320, 高さ 240, 塗りつぶしの色 (20, 50, 200)
const Image image(320, 240, Color(20, 50, 200));
const Texture texture(image);
while (System::Update())
{
texture.draw();
}
}

# include <Siv3D.hpp>
void Main()
{
Image(480, 320, Palette::Yellow).save(L"Tutorial-RGB.png");
// 第 2 引数の画像の r 成分を、新しく作る画像の a 成分とする
const Image image(L"Tutorial-RGB.png?raw=true" width="640" height="480">;
const Texture texture(image);
while (System::Update())
{
Rect(100, 100, 200, 200).draw(Palette::Orange);
texture.draw(Mouse::Pos());
}
}

# include <Siv3D.hpp>
void Main()
{
// 第 2 引数の画像の r 成分を、新しく作る画像の a 成分とする
const Image image(Palette::White, L"Example/Windmill.png");
const Texture texture(image);
while (System::Update())
{
Rect(100, 100, 200, 200).draw(Palette::Orange);
texture.draw(Mouse::Pos());
}
}

# include <Siv3D.hpp>
void Main()
{
const Image image(L"Example/Windmill.png");
const Texture texture(image);
while (System::Update())
{
texture.draw();
const Point pos = Mouse::Pos();
if (0 <= pos.x && pos.x < image.width
&& 0 <= pos.y && pos.y < image.height)
{
// カーソルがさしている位置の色を取得
const Color pixelColor = image[pos.y][pos.x];
Circle(400, 400, 50).draw(pixelColor);
}
}
}

# include <Siv3D.hpp>
void Main()
{
Image image(320, 240, Palette::White);
for (int32 y = 0; y < image.height; ++y)
{
for (int32 x = 0; x < image.width; ++x)
{
image[y][x] = Color(y, x / 2, 200);
}
}
const Texture texture(image);
while (System::Update())
{
texture.draw();
}
}

# include <Siv3D.hpp>
void Main()
{
Image image(320, 240, Palette::White);
Rect(40, 40, 100, 40).overwrite(image, Palette::Red);
Circle(200, 100, 80).overwrite(image, Palette::Blue);
Line({ 100, 200 }, { 300, 50 }).overwrite(image, 5, Palette::Black);
// 透過して色をブレンドする場合は write()
Circle(100, 200, 80).write(image, Color(255, 127, 0, 200));
const Texture texture(image);
while (System::Update())
{
texture.draw();
}
}

# include <Siv3D.hpp>
void Main()
{
// 画像内の位置 (200, 100) から 幅 180, 高さ 190 の領域を切り抜いた Image から Texture を作成
const Texture texture(Image(L"Example/Windmill.png").clip(200, 100, 180, 190));
while (System::Update())
{
texture.draw();
}
}

# include <Siv3D.hpp>
void Main()
{
const Texture texture(
Image(L"Example/Windmill.png")
.floodFilled({ 30, 30 }, Palette::Yellow, FloodFillConnectivity::Value8, 50, 50));
while (System::Update())
{
texture.draw();
}
}

# include <Siv3D.hpp>
void Main()
{
const Texture texture(Image(L"Example/Windmill.png").mosaiced(10, 10));
while (System::Update())
{
texture.draw();
}
}

# include <Siv3D.hpp>
void Main()
{
const Texture texture(Image(L"Example/Windmill.png").grayscaled());
while (System::Update())
{
texture.draw();
}
}

# include <Siv3D.hpp>
void Main()
{
const Texture texture(Image(L"Example/Windmill.png").sepiaed());
while (System::Update())
{
texture.draw();
}
}

# include <Siv3D.hpp>
void Main()
{
const Texture texture(Image(L"Example/Windmill.png").gaussianBlurred(15, 15));
while (System::Update())
{
texture.draw();
}
}

# include <Siv3D.hpp>
void Main()
{
const Texture texture(Image(L"Example/Windmill.png").spreaded(5, 5));
while (System::Update())
{
texture.draw();
}
}

# include <Siv3D.hpp>
void Main()
{
const Texture texture(Image(L"Example/Windmill.png").negated());
while (System::Update())
{
texture.draw();
}
}

# include <Siv3D.hpp>
void Main()
{
const Texture texture(Image(L"Example/Windmill.png").thresholded(127));
while (System::Update())
{
texture.draw();
}
}

# include <Siv3D.hpp>
void Main()
{
Image image(L"Example/Windmill.png");
image.fill(Palette::Orange);
const Texture texture(image);
while (System::Update())
{
texture.draw();
}
}

# include <Siv3D.hpp>
void Main()
{
const Image image(L"Example/Windmill.png");
const Texture texture(image.scaled(400, 400));
const Texture texture2(image.scaled(0.5));
while (System::Update())
{
texture.draw();
texture2.draw();
}
}
- Siv3D の基本
- 図形を描く
- テクスチャを描く
- テキストを描く
- 文字列と数値の変換
- キーボード入力
- マウス入力
- サウンドの再生
- MIDI の再生
- ウィンドウと背景
- 図形のあたり判定
- 乱数
- ダイアログ
- ドラッグ & ドロップ
- アプリの状態
- テキストファイル
- INI, CSV, JSON
- バイナリファイル
- GUI
- アセット管理
- 画像編集
- Web カメラ
- マイク入力
- 経過時間の測定
- HSV カラー
- ファイルダウンロード
- 3D 描画
- 2D のレンダーステート
- 3D のレンダーステート
- パーティクル
- スクリーンショット
- アプリケーションの公開
- さらに学ぶには
- アプリランチャーを作ろう
- 音楽プレイヤーを作ろう
- 横スクロールゲームを作ろう
- ドット絵エディタを作ろう
- シーン遷移をサポートする SceneManager の使い方
- Siv3D ミニサンプル集
- タスクシステムを使う
- スケッチ
- 画像ビューアー
- オーディオスペクトラム
- マイク入力スペクトラム
- 文字色の反転
- 天気予報
- ドットお絵かき
- 15パズル
- ブロックくずし
- 時計
- 音楽プレイヤー
- ピアノ
- ライフゲーム
- シーン管理
- 地球
- 3Dシーン
- 3D交差判定
- Wooden Mirror
- シューティングゲーム
- Image to Polygon
- Sketch to Polygon
- 軌跡
- Plot3D
- テンポとピッチの変更
- 長方形の影
- Twitterクライアント
- Polygon to Mesh
- 3Dテキスト
- アプリ終了の確認
- 地形の生成
- アーカイブファイル
- GUIのアニメーション
- Aero Glassエフェクト
- Glitch
- リンクテキスト
- 付箋
- シーン切り替え(シルエット)
- MIDIシーケンサー
- 数つなぎ
- 画面を揺らす
- 対称定規
- aobench
- MIDIビジュアライザー
- 電卓
- 手書き文字認識
- 顔検出
- 音声合成
- Image to PhysicsBody