4点指定のBITMAP表示

アバター
トム
記事: 4
登録日時: 15年前

4点指定のBITMAP表示

投稿記事 by トム » 14年前

2011y02m27d_185832386.jpg
2011y02m27d_185832386.jpg (13.79 KiB) 閲覧数: 71 回
できました。
でもこれだと回転表示とほとんど処理時間かわらないので
回転表示作る意味なかった。
次は何やろう。

CODE:

// 四点指定
void MYBITMAP::Draw4Point(HDC hdc, POINT pts[4])
{
	if(((BITMAPINFOHEADER*)bmi)->biBitCount != 24)
		return;

	int x_max = max(max(pts[0].x,pts[1].x),max(pts[2].x,pts[3].x));
	int x_min = min(min(pts[0].x,pts[1].x),min(pts[2].x,pts[3].x));
	int y_max = max(max(pts[0].y,pts[1].y),max(pts[2].y,pts[3].y));
	int y_min = min(min(pts[0].y,pts[1].y),min(pts[2].y,pts[3].y));

	int w = x_max - x_min;
	int h = y_max - y_min;
	int ww = calcww(RGB24, w);

	POINT org = {x_min, y_max};
	int x = x_min;
	int y = y_min;

	char* pp = new char[h*ww];
	memset(pp,255,h*ww);

	MYMATRIX A = {pts[1].x - pts[0].x, pts[3].x - pts[0].x, pts[1].y - pts[0].y, pts[3].y - pts[0].y};
	MYMATRIX B = {pts[1].x - pts[2].x, pts[3].x - pts[2].x, pts[1].y - pts[2].y, pts[3].y - pts[2].y};
	MYMATRIX IA = MYInvertMatrix(A);
	MYMATRIX IB = MYInvertMatrix(B);
	DPOINT ef;
	DPOINT ef2;

	int w2;
	int h2;

	for(int i=0; i biBitCount != 24)
		return;

	double arg2 = atan2((double)p.y-c.x,(double)p.x-c.x) + arg;

	double sn = sin(arg2);
	double cs = cos(arg2);

	// sg:四捨五入
	int w = sg(getw() * abs(cs) + geth() * abs(sn));
	int h = sg(getw() * abs(sn) + geth() * abs(cs));
	int ww = calcww(RGB24, w);

	int ii;
	int jj;

	char* pp = new char[h*ww];

	memset(pp, 255, h*ww);

	double w2 = (double)w / 2;
	double h2 = (double)h / 2;

	for(int i = 0; i < h; i++)
	{
		for(int j = 0; j < w; j++)
		{
			jj = sg((double)getw() / 2 + (j - w2) * cs - (i - h2) * sn);
			ii = sg((double)geth() / 2 + (j - w2) * sn + (i - h2) * cs);

			if(0 <= ii && ii < geth() && 0 <= jj && jj < getw())
				memcpy(pp + i * ww + j * 3, (char*)vp + ii * getww() + jj * 3, 3);
		}
	}

	int x = int(c.x + (p.x - c.x) * cs - (p.y - c.y) * sn) - w / 2;
	int y = int(c.y + (p.x - c.x) * sn + (p.y - c.y) * cs) - h / 2;

	MYBITMAP bm(RGB24, w, h, pp);

	delete []pp;

	bm.Draw(hdc, x, y, true, false);
}
2011y02m27d_185832386.jpg
2011y02m27d_185832386.jpg (13.79 KiB) 閲覧数: 71 回

コメントはまだありません。