画像処理入門 > その他 > 四角形の枠を作成

四角形の枠を作成


四角形の枠を作成
指定した座標で四角形の枠を作成するプログラムです。
※サンプルは24bitのみ対応

サンプルプログラム
プログラムはこちら /* in : 横は4バイト */ void rectangle(unsigned char *img, int height, int width, int channel, int xStart, int xEnd, int yStart, int yEnd, int large, int red, int blue, int green){ int i, j; int widthStep; widthStep = width * channel; if( (widthStep % 4) != 0){ widthStep = widthStep + 4 - widthStep%4; } for(i = yStart; i <= yEnd; ++i){ for(j = 0; j < large; ++j){ img[i * widthStep + (xStart + j) * 3] = blue; img[i * widthStep + (xStart + j) * 3 + 1] = green; img[i * widthStep + (xStart + j) * 3 + 2] = red; img[i * widthStep + (xEnd - j) * 3] = blue; img[i * widthStep + (xEnd - j) * 3 + 1] = green; img[i * widthStep + (xEnd - j) * 3 + 2] = red; } } for(j = xStart; j <= xEnd; ++j){ for(i = 0; i < large; ++i){ img[(yStart + i) * widthStep + j * 3] = blue; img[(yStart + i) * widthStep + j * 3 + 1] = green; img[(yStart + i) * widthStep + j * 3 + 2] = red; img[(yEnd - i) * widthStep + j * 3] = blue; img[(yEnd - i) * widthStep + j * 3 + 1] = green; img[(yEnd - i) * widthStep + j * 3 + 2] = red; } } }