|
동욱님이 넘 정확하게 설명해 주셔서 할 말은 없구요.. 이전에 ScanLine에 관해서 답변 올린적이 있었는데, 그 소스를 조금 변경해서 하시려는 작업에 맞춰 보았습니다.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
#define WIDTH 300
#define HEIGHT 300
int PIXEL[300][300];
int itX, itY;
RGBTRIPLE *rtColor;
Graphics::TBitmap *BITMAP = new Graphics::TBitmap;
// 임의 Pixels 지정. 바탕색은 하얀색, 그리고 빨간색 대각선 선 하나만 그림
FillMemory(PIXEL, sizeof(PIXEL), 0x00FFFFFF);
for(itX = 0; itX < WIDTH; itX ++)
PIXEL[itX][itX] = clMaroon;
// 비트맵 설정
BITMAP->PixelFormat = pf24bit;
BITMAP->Width = WIDTH;
BITMAP->Height = HEIGHT;
// ScanLine 포인터를 받아 값을 바꾼다
for(itY = 0; itY < HEIGHT; itY ++) {
rtColor = (RGBTRIPLE *)BITMAP->ScanLine[itY];
for(itX = 0; itX < WIDTH; itX ++) {
rtColor[itX].rgbtBlue = (PIXEL[itX][itY] >> 16) & 0xFF;
rtColor[itX].rgbtGreen = (PIXEL[itX][itY] >> 8) & 0xFF;
rtColor[itX].rgbtRed = (PIXEL[itX][itY]) & 0xFF;
}
}
Canvas->Draw(50, 50, BITMAP);
delete BITMAP;
}
//---------------------------------------------------------------------------
빌더매니아 님이 쓰신 글 :
: void __fastcall TForm1::Button1Click(TObject *Sender)
:
: {
: Graphics::TBitmap *pBitmap = new Graphics::TBitmap();
: // This example shows drawing directly to the Bitmap
: Byte *ptr;
: try
: {
: pBitmap->LoadFromFile("C:\\Program Files\\Common Files\\Borland Shared\\Images\\Splash\\256color\\factory.bmp ");
: for (int y = 0; y < pBitmap->Height; y++)
: {
: ptr = (Byte *)pBitmap->ScanLine[y];
: for (int x = 0; x < pBitmap->Width; x++)
:
: ptr[x] = (Byte)y;
: }
: Canvas->Draw(0,0,pBitmap);
: }
: catch (...)
: {
: ShowMessage("Could not load or alter bitmap");
: }
: delete pBitmap;
: }
:
: 그런데요..
: 위의 코드 "ScanLine"에 대한 example code인데요,
: (Byte *)pBitmap->ScanLine[y]; 에서 (Byte *)로 캐스팅을 하쟎아요?
: 그러면 ScanLine 메소드가 먹히질 않아요.
: 혹시 이유를 아시면 좀 가르쳐주실 수 있을까요?
:
|