초간단 bmp 포맷으로 저장

간단하게 작성해본 bmp 파일 핸들링 예제.
Freeimage 는 정말이지.. 심플하며.. 최고다.

#include <FreeImage.h>

void main(void)
{
	FIBITMAP *bitmap = FreeImage_Allocate(512, 512, 32, FI_RGBA_RED_MASK,
		FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
	if (bitmap) {
		int bytespp;
		int y;
		int x;
		int width = FreeImage_GetWidth(bitmap);
		int height = FreeImage_GetHeight(bitmap);
		int line = FreeImage_GetLine(bitmap);

		bytespp = line / width;
		for(y = 0; y < height; y++) {
			char *bits = FreeImage_GetScanLine(bitmap, y);
			for(x = 0; x < width; x++) {
				// Set pixel color to green with a transparency of 128
				bits[FI_RGBA_RED]   = 0;
				bits[FI_RGBA_GREEN] = 255;
				bits[FI_RGBA_BLUE]  = 0;
				bits[FI_RGBA_ALPHA] = 128;
				// jump to next pixel
				bits += bytespp;
			}
		}
		
		FreeImage_Save(FIF_BMP, bitmap, "test.bmp", PNG_DEFAULT);

		FreeImage_Unload(bitmap);
	}
}

FreeImage with wxWidgets

wxWidgets과 FreeImage의 조합이 필요하다면 아래의 소스를 분석해본다.
http://sourceforge.net/projects/comical/

http://sourceforge.net/projects/kujawiak/files/

아래의 코드도 보고.
출처: http://kldp.org/node/88572

void MyFrame::Test(wxCommandEvent& event)
{
	if ( false == m_image.load("a.jpg") )
	{
		wxMessageBox(_T("can not load"), _T("warning"), wxOK, this);
		return;
	}
 
	m_image.convertTo32Bits();
 
 
	{
		int width = m_image.getWidth();
		int height = m_image.getHeight();
		int scanWidth = m_image.getScanWidth();
 
		// Create the wxBitmap object
		m_pBitmap = new wxBitmap(width, height, 32);
 
		typedef wxPixelData<wxBitmap, wxAlphaPixelFormat> PixelData;
		wxAlphaPixelData data(*m_pBitmap);
		data.UseAlpha();
 
		PixelData::Iterator p(data);
 
		// Iterate the image lines:
		for(int y = height-1; y >= 0; --y)
		{
		     PixelData::Iterator rowStart = p;
 
		     // Iterate the current line pixels:
		     BYTE* pLineData = m_image.getScanLine(y);
 
		     for(int x = 0; x < width; ++x, ++p, pLineData += 4)
		     {
		          p.Red() = pLineData[2];
		          p.Green() = pLineData[1];
		          p.Blue() = pLineData[0];
		          p.Alpha() = pLineData[3];
		     }
 
		     p = rowStart;
		     p.OffsetY(data, 1);
		}
	}
	wxClientDC dc(this);
	dc.DrawBitmap(*m_pBitmap, wxPoint(0,0));
}

아래는 FreeImage를 이용하여 이미지를 보여주는 예제이다.
http://www.codeproject.com/KB/graphics/freeimage_display_demo.aspx

FreeImage

홈페이지: http://freeimage.sourceforge.net/

FreeImage is an Open Source library project for developers who would like to support popular graphics image formats like PNG, BMP, JPEG, TIFF and others as needed by today’s multimedia applications. FreeImage is easy to use, fast, multithreading safe, compatible with all 32-bit versions of Windows, and cross-platform (works both with Linux and Mac OS X).

다운로드: 3.13.1, 3.15.0