[Gdal-dev] show raster with gdi

Chapman, Martin MChapman at sanz.com
Sat Dec 10 13:05:31 EST 2005


With GDI+:  Note the use of the 3 point DrawImage() function that allows
drawing of a rotated parallelgram.

vector< int> vBands = spRasterLayer->GetBandSelection();
			int nBandCount = (int) vBands.size();

			void* pDest = NULL;
			void* pSrc = NULL;
			CVPPtr< IVPRaster> spRaster;
	
spRaster.Attach(spRasterSet->GetRaster(nOverview, &sourceRect,
&destRect, &vBands, true, (void*) &ProgressFunc));
			int nDestWidth =
spRaster->GetBand(0)->GetWidth();
			int nDestHeight =
spRaster->GetBand(0)->GetHeight();
			if (nDestWidth < 1 || nDestHeight < 1) return;

			PixelFormat pixelFormat = PixelFormat24bppRGB;
			CDIBSection* m_pDIBSection = new CDIBSection();
			void* pBytes = spRaster->GetBytes(NULL, &vBands,
RASTER_RGB);
			m_pDIBSection->Create(nDestWidth, nDestHeight,
24);
			unsigned int dibwidth =
m_pDIBSection->GetTotalWidth();
			void* dest = (void*) m_pDIBSection->GetBits();
			void* src = (void*) pBytes;
			for (int row = 0; row < nDestHeight; row++)
			{
				pDest = ((unsigned char*)dest) + row *
dibwidth * 3;
				pSrc = ((unsigned char*)src) + row *
nDestWidth * 3;
				memcpy(pDest, pSrc, nDestWidth * 3);
			}

			#ifdef _DEBUG
			#undef new
			Bitmap* pBitmap = new
Bitmap(m_pDIBSection->Width(), 
	
m_pDIBSection->Height(), 
	
dibwidth * 3, 
	
pixelFormat, 
	
(BYTE*) m_pDIBSection->GetBits());
			#define new DEBUG_NEW
			#else
			Bitmap* pBitmap = new
Bitmap(m_pDIBSection->Width(), 
	
m_pDIBSection->Height(), 
	
dibwidth * 3, 
	
pixelFormat, 
	
(BYTE*) m_pDIBSection->GetBits());
			#endif

PointF parallelogram[3] = {PointF((REAL)nULXP, (REAL)-nULYP), 
	
PointF((REAL)nURXP, (REAL)-nURYP), 
	
PointF((REAL)nLLXP, (REAL)-nLLYP)};

			Status status = pMemGraphics->DrawImage(pBitmap,
parallelogram, 3);

			if (pBitmap) delete pBitmap;
			if (m_pDIBSection) delete m_pDIBSection;
			if (pBytes) delete [] pBytes;
			if (spRaster.p) spRaster.Release();

-----Original Message-----
From: gdal-dev-bounces at lists.maptools.org
[mailto:gdal-dev-bounces at lists.maptools.org] On Behalf Of
alucas at srtec.com
Sent: Saturday, December 10, 2005 8:59 AM
To: Gdal-dev at lists.maptools.org
Subject: [Gdal-dev] show raster with gdi

Hello,

I'm writing a simple application that show an image raster. I'm writting
this for Windowsation with vc++ 6.0 with MFC, and in my application I've
the raster into a buffer (GByte array i.e). So, now I want to show the
raster in my MFC Appication, for this, I was readed that the best choice
is to use DIB Sections, but, I don't have any experience with GDI...
Anybody can show to me any sample code (vc++ with mfc) for painting the
content of buffer into a dib section?

Thanks.


_______________________________________________
Gdal-dev mailing list
Gdal-dev at lists.maptools.org
http://lists.maptools.org/mailman/listinfo/gdal-dev




More information about the Gdal-dev mailing list