掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
jpeg画像を90度回転させる (ID:61079)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
90度回転は、 rotated.SetPixel(h - y - 1, x, source.GetPixel(x, y)); でしたね、間違ってました。 (ついでにGetPixelAdressはGetBitsの方がよかったかも・・・) お詫びにバッファ直操作の90度回転を作ってみたので置いときますが、 kureさんのおっしゃるように、なるべく画像処理の仕組みを理解してからやった方がいいと思います。 ↓この本なんかとっつきやすいかも? http://www.amazon.co.jp/exec/obidos/ASIN/479800958X/ #include <atlimage.h> int main() { CImage source; source.Load("source.jpg"); int w = source.GetWidth(); int h = source.GetHeight(); int bpp = source.GetBPP(); int sourcePitch = source.GetPitch(); unsigned char *sourceBuffer = (unsigned char *)source.GetBits(); if(bpp < 8) return false; // bpp < 8 のときは略 CImage rotated; rotated.Create(h, w, bpp); int rotatedPitch = rotated.GetPitch(); unsigned char *rotatedBuffer = (unsigned char *)rotated.GetBits(); int bytepp = bpp / 8; for(int x = 0 ; x < w ; ++x){ for(int y = 0 ; y < h ; ++y){ int destX = h - y - 1; int destY = x; unsigned char *read = sourceBuffer + x * bytepp + y * sourcePitch; unsigned char *write = rotatedBuffer + destX * bytepp + destY * rotatedPitch; for(int c = 0 ; c < bytepp ; ++c) *write++ = *read++; } } rotated.Save("rotated.jpg"); return 0; }
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.