U E D R S I H C RSS
ID
Password
Join
์ง€๊ตฌ์™€ ๋Œ€๋ฅ™๊ณผ ๋Œ€์–‘์˜ ํ˜•ํƒœ๋ฅผ ๋ฐœ๊ฒฌํ•˜๋Š” ๋ฐ ์žˆ์–ด ๊ฐ€์žฅ ํฐ ์žฅ์• ๋ฌผ์€ ๋ฌด์ง€๊ฐ€ ์•„๋‹ˆ๋ผ ์ง€์‹์˜ ๋ง์ƒ์ด์—ˆ๋‹ค. โ€•๋‹ค๋‹ˆ์—˜ J.๋ถ€์–ด์Šคํ‹ด

์ฃผ์˜์‚ฌํ•ญ #

  • ์—ฌ๊ธฐ ์ œ์‹œ๋œ ์˜ˆ์ œ ํด๋ž˜์Šค๋Š” ๊ทธ์ € ๋งŒ๋“ค์–ด์ง„ HDC์— ๊ทธ๋ฆฌ๋Š” ๋ถ€๋ถ„๋งŒ ๊ตฌํ˜„๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ ํ……๋นˆ DDB๋ฅผ ์ƒ์„ฑํ•œ๋‹ค์Œ ๋ณต์‚ฌํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.
  • [http]SetDIBitsToDevice()์„ ์‚ฌ์šฉํ•˜์—ฌ ์ƒ์„ฑํ•œ DIB ๋ฐ์ดํƒ€๋ฅผ ์ง€์ •ํ•œ HDC์— ๊ทธ๋ฆฝ๋‹ˆ๋‹ค.

์†Œ์Šค #

DIB.hpp #

#ifndef ___DIB_H___
#define ___DIB_H___

#include <windows.h>

struct DIB 
{
	BITMAPFILEHEADER *hFileBitmap;
	BITMAPINFOHEADER *hInfoBitmap;
	int Width, Height;
	BYTE *pBitmap;

	TDIB();
	virtual ~TDIB();

	// DIB ํ™”์ผ์„ ์ฝ์–ด๋“ค์ธ๋‹ค. (ํ™”์ผ๋ช…์— ์ „์ฒด Path๋ฅผ ์ง‘์–ด๋„ฃ๋Š”๋‹ค)
	BOOL LoadFromFullPathFile(LPTSTR FullPathFilename);
	// DIB ํ™”์ผ์„ ์—ญ์‹œ ์ฝ์–ด๋“ค์ธ๋‹ค. ^_^ (ํ˜„์žฌ ๋””๋ ‰ํ† ๋ฆฌ์—์„œ ์ฝ๋Š”๋‹ค)
	BOOL LoadFromFile(LPTSTR Filename);
	// DIBํ™”์ผ์„ ์ฝ์–ด๋“ค์˜€๋‚˜?
	inline BOOL IsLoaded() {return (hFileBitmap != NULL);};
	// ์›ํ•˜๋Š” HDC์— ์ถœ๋ ฅํ•œ๋‹ค.
	void DrawBitmap(HDC hdc, int x, int y);
};

#endif 

DIB.cpp #

// TDIB.cpp: DIBํ™”์ผ ์ œ์–ด ํด๋ž˜์Šค
//
//////////////////////////////////////////////////////////////////////

#include "TDIB.h"
#include <stdio.h>

//////////////////////////////////////////////////////////////////////
TDIB::TDIB()
{
	// DIB๊ฐ€ ์ฝ์–ด๋“ค์ด์ง€ ์•Š์€ ์ƒํƒœ๋กœ ํ‘œ์‹œํ•œ๋‹ค.
	hFileBitmap = NULL;
}

TDIB::~TDIB()
{
	// ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ•ด์ œํ•œ๋‹ค.
	if (hFileBitmap != NULL) free(hFileBitmap);
}

//////////////////////////////////////////////////////////////////////
BOOL TDIB::LoadFromFullPathFile(LPTSTR Filename)
{
	HANDLE hFile;
	DWORD FileSize, dwRead;

	// ํ™”์ผ์„ ์—ฐ๋‹ค.
	hFile = CreateFile(Filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL);
	// ํ™”์ผ์„ ์ฝ์ง€ ๋ชปํ•˜๋ฉด ๋๋‚ธ๋‹ค.
	if (hFile == INVALID_HANDLE_VALUE) 
		return FALSE;

	// ๋น„ํŠธ๋งตํ™”์ผ์˜ ํฌ๊ธฐ๋ฅผ ๊ตฌํ•œ๋‹ค.
	FileSize = GetFileSize(hFile, NULL);

	// ํ™”์ผ์ •๋ณดํ—ค๋”์— ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ํ• ๋‹น๋˜์–ด์žˆ์œผ๋ฉด ํ•ด์ œํ•˜๊ณ  ๋‹ค์‹œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํ• ๋‹นํ•œ๋‹ค.
	if (hFileBitmap != NULL) free(hFileBitmap);
	hFileBitmap = (BITMAPFILEHEADER *)malloc(FileSize);
	
	// ํ™”์ผ๋กœ๋ถ€ํ„ฐ ๋น„ํŠธ๋งต์„ ์ฝ์–ด๋“ค์ธ๋‹ค.
	ReadFile(hFile, hFileBitmap, FileSize, &dwRead, NULL);
	// ๋‹ค์ฝ์—ˆ์œผ๋‹ˆ ํ™”์ผ์„ ๋‹ซ๋Š”๋‹ค.
	CloseHandle(hFile);

	// pBitmap์— ๋น„ํŠธ๋งต์ •๋ณด๊ฐ€ ๋‹ด๊ฒจ์žˆ๋Š” ๋ถ€๋ถ„์˜ ์ฃผ์†Œ๋ฅผ ์ง€์ •ํ•œ๋‹ค.
	pBitmap = (PBYTE) hFileBitmap + (hFileBitmap->bfOffBits);

	// BITMAPINFOHEADER์˜ ์ฃผ์†Œ๋ฅผ ์ง€์ •ํ•œ๋‹ค.
	hInfoBitmap = (BITMAPINFOHEADER *) ((PBYTE) hFileBitmap + sizeof(BITMAPFILEHEADER));
	
	// ๋น„ํŠธ๋งต์˜ ํญ๊ณผ ๋†’์ด ์ •๋ณด๋ฅผ ์ €์žฅํ•œ๋‹ค.
	Width = hInfoBitmap->biWidth;
	Height = hInfoBitmap->biHeight;

	return TRUE;
}

BOOL TDIB::LoadFromFile(LPTSTR Filename)
{
	TCHAR tmpCurrDir[256], tmpFullPathFilename[256];

	GetCurrentDirectory(256, tmpCurrDir);
	sprintf(tmpFullPathFilename, "%s\\%s", tmpCurrDir, Filename);
	return LoadFromFullPathFile(tmpFullPathFilename);
}

void TDIB::DrawBitmap(HDC hdc, int x, int y)
{
	SetDIBitsToDevice(
		hdc, x, y, Width, Height, 
  0, 0,
  0,         // first scan line in array
  Height,         // number of scan lines
  pBitmap,
  (BITMAPINFO *)hInfoBitmap,
  DIB_RGB_COLORS);
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2010-10-28 12:42:54
Processing time 0.5294 sec