image.cpp

来自「Visual C++角色扮演游戏程序设计(附带CD源代码)作者: (日)坂本千寻」· C++ 代码 · 共 66 行

CPP
66
字号
//
// 24Bits/Pixel 图像
//
// Copyright (c) 2000-2001 Chihiro.SAKAMOTO (HyperWorks)
//
#include "StdAfx.h"
#include "Application.h"
#include "Image.h"
#include "File.h"
#include "Misc.h"
#include "dc.h"

//
// 构造函数
//
CImage::CImage(int width, int height)
{
	Create(width, height);
}

//
// 产生DIB
//
BOOL CImage::Create(int width, int height)
{
	return CDib::Create(width, height, 24);
}

//
// 复制区域
//
void CImage::Copy(const CImage *image, const CRect &rect)
{
	int len = rect.Width() * 3;
	for (int y=rect.top; y<rect.bottom; y++) {
		memcpy(GetBits(rect.left, y), image->GetBits(rect.left, y), len);
	}
}

//
// 复制(考虑了透明颜色)
//
void CImage::MixImage(const CImage *image, const CRect &rect, COLORREF trans_color)
{
	const unsigned char trans_b = GetBValue(trans_color);
	const unsigned char trans_g = GetGValue(trans_color);
	const unsigned char trans_r = GetRValue(trans_color);
	
	for (int y=rect.top; y<rect.bottom; y++) {
		byte_t *p = (byte_t *)GetBits(rect.left, y);
	const byte_t *q = (byte_t *)image->GetBits(rect.left, y);
	for (int x=rect.left; x<rect.right; x++) {
		const byte_t b = *q++;
	const byte_t g = *q++;
	const byte_t r = *q++;
	
	if (b != trans_b || g != trans_g || r != trans_r) {
		p[0] = b;
		p[1] = g;
		p[2] = r;
	}
	p += 3;
}
}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?