slice a "BIG" image into many "SMALL" images

Win32 Programming

    Next

  • 1. Characters intermittently become invisible
    I have been runing XP on my computer for several years without problems. A month or two ago I started occasionally experiencing a problem: large sections of text are not visible. This happens on all running applications. The only reliable work around I have found is to reboot. Today I noticed another symptom: when the flowerbox screen saver comes up, rather than the graphic object, I see a moving white box with the text "Could not find any compatible Direct3D devices." I have been trying to localize the problem but have not had much success. I can only think of two changes I made to my machine around the time the problem started happening: I installed the VoiceRite client for Lotus Notes and fixed a font resource leak in my own product. Has anyone ever seen this problem, or have any idea what could cause it? BTW The problem sometimes continues to happen even if I shut down all running applications and restart them. Thank you. David Liebtag

slice a "BIG" image into many "SMALL" images

Postby fulltime » Sat, 06 May 2006 14:17:08 GMT

hi all,

i have this image, 600*400 pixels n i wan to slice it into many small
images each of 12*16 and save all these small images as bmp file..
using CDC n CBitmap, below are the codes which i have come up with so
far.. however, i am lost as in how shld i save the small images into
bmp file. Can someone pls help me? besides saving the small images into
a bmp file, are they any other ways i can view the contents of the
small images to ensure wat i did is correct so far?

regards FT

#include <iostream.h>

#include <afxwin.h>

void main(void)
{

	CBitmap bmpBig;
	CFile file;

	HANDLE	hBitMap = LoadImage(0, "D:\\Foo\\01.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE);

	bmpBig.Attach (hBitMap); // Load big bmp into bmpBig
	CDC dcBig;
	dcBig.CreateCompatibleDC(NULL);
	CBitmap* pBOldBmp = dcBig.SelectObject(&bmpBig);	// Create dcBig and
select bmpBig into it.

	CBitmap bmpSmall;	// Create empty small bitmap with correct dimensions
	HDC dc= CreateCompatibleDC(NULL);
	BITMAPINFO i;
	ZeroMemory( &i.bmiHeader, sizeof(BITMAPINFOHEADER) );
	i.bmiHeader.biWidth=12;     // Set size you need
	i.bmiHeader.biHeight=16;    // Set size you need
	i.bmiHeader.biPlanes=1;
	i.bmiHeader.biBitCount=1; // Can be 8, 16, 32 bpp or
							   // other number
	i.bmiHeader.biSizeImage=0;
	i.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
	i.bmiHeader.biClrUsed= 0;
	i.bmiHeader.biClrImportant= 0;
	VOID *pvBits;
	HBITMAP hbmp= CreateDIBSection( dc, &i,DIB_RGB_COLORS,&pvBits,NULL,0
); //create empty bitmap
	bmpSmall.Attach (hbmp);


	CDC dcSmall; 	// Create dcSmall and select bmpSmall into it.
	dcSmall.CreateCompatibleDC(NULL);
	CBitmap* pSOldBmp = dcSmall.SelectObject(&bmpSmall);

	BitBlt( dcBig, 0, 0, 12, 16,dcSmall, 0, 0, SRCCOPY ); // use bitblt to
blit                          a
             rectangle from dcBig to dcSmall.



	// Unselect bmpSmall from dcSmall
	// Save bmpSmall to .bmp file.
	
	

	dcBig.SelectObject(pBOldBmp);
	dcSmall.SelectObject(pSOldBmp);


Re: slice a "BIG" image into many "SMALL" images

Postby Kellie Fitton » Sat, 06 May 2006 23:28:59 GMT

Hi,

You can use the following APIs to save a bitmap into a file:

	GlobalAlloc()
	GetDIBits()
	CreateFile()
	WriteFile()
	CloseHandle()

	//* cleanUp...

	GlobalFree()

 http://www.**--****.com/ 

 http://www.**--****.com/ 

 http://www.**--****.com/ 

 http://www.**--****.com/ 

 http://www.**--****.com/ 

 http://www.**--****.com/ 

Hope these suggestions helps,

Kellie.



Return to Win32 Programming

 

Who is online

Users browsing this forum: No registered users and 28 guest