Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

SikCiv

Bitmap pixel offset c++ utility?

This topic is 6263 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a utility that loads a Bitmap file and lets you click on various points of the bitmap whilst outputting the points to a file - preferably a C++ array? The reason I ask is my game uses graphic based letters from a single bitmap, evert time I create a new set, I have to manually get the offsets in Paint and enter it in my CPP files .. can be very time consuming.

  Downloads:  ZeroOne Realm

Share this post


Link to post
Share on other sites
Advertisement
I was thinking of that, though I''m not quite sure how to assign a bitmap to a window etc. and MFC can be quite complicated on occasion. If there is a util available I''ll use that, otherwise Ill create my own.

  Downloads:  ZeroOne Realm

Share this post


Link to post
Share on other sites
hmm...i dont think there are any but i might be able to make one real quick

just tell me if you want me to and ill see what i can do

Share this post


Link to post
Share on other sites
If u have some spare time that would be great

Basically I need an MFC app that loads a bitmap in its window and has a crosshair cursor that can tell me the offset on each click. I can do the file output stuff no probs.

Share this post


Link to post
Share on other sites
nevermind i just made it maximized
this took about 10 minutes to do
the only comments are where you can do the file stuff...


#include
#include



HINSTANCE hInst=NULL;
HWND main=NULL;
HBITMAP bmp=NULL;
HDC tempdc=NULL;

int bwidth,bheight;



LRESULT CALLBACK WindowProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_MOUSEMOVE:
{
if(LOWORD(lParam) {
char t[30];

sprintf(t,"Coordinates: (%d, %d)",LOWORD(lParam),HIWORD(lParam));
SetWindowText(main,t);
}
}
break;
case WM_LBUTTONDOWN:
{
int x=LOWORD(lParam);
int y=HIWORD(lParam);

// this x and y are thr coordiantes of the pixel on the bitmap
// do the file stuff here
}

case WM_CLOSE:
{
PostQuitMessage(0);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC dc=BeginPaint(hwnd,&ps);
if(tempdc)
{
BitBlt(dc,0,0,bwidth,bheight,tempdc,0,0,SRCCOPY);
}
EndPaint(hwnd,&ps);
}
break;
default:
{
return DefWindowProc(hwnd,message,wParam,lParam);
}
}

}




int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int iCmdShow)
{
MSG msg;
WNDCLASSEX wcex;
UINT width,height;

hInst=hInstance;

width=500;
height=400;

ZeroMemory((void *)&wcex,sizeof(wcex));

wcex.cbSize=sizeof(WNDCLASSEX);
wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW);
wcex.hCursor=LoadCursor(NULL,IDC_CROSS);
wcex.hIcon=wcex.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
wcex.hInstance=hInstance;
wcex.lpfnWndProc=WindowProc;
wcex.style=CS_DBLCLKS;
wcex.lpszClassName="BitmapLoader Window";

if(!RegisterClassEx(&wcex))
{
return 0;
}

main=CreateWindowEx(0,"BitmapLoader Window","", WS_OVERLAPPEDWINDOW,50,50,width,height,NULL,NULL,hInstance,NULL);

if(!main)
{
return 0;
}

ShowWindow(main,SW_SHOWMAXIMIZED);


char file[MAX_PATH];
OPENFILENAME ofn;

ZeroMemory(&ofn, sizeof(OPENFILENAME));
ZeroMemory(file, sizeof(file));

ofn.lStructSize=sizeof(OPENFILENAME);
ofn.lpstrTitle="Choose File...";
ofn.hwndOwner=main;
ofn.lpstrFilter="Bitmaps (*.bmp)\0*.bmp\0All Files (*.*)\0*.*\0","bmp";
ofn.nFilterIndex=0;
ofn.lpstrDefExt="bmp";
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
ofn.lpstrFile = file;
ofn.nMaxFile = MAX_PATH;
//ofn.lpstrInitialDir = NULL;

if(!GetOpenFileName(&ofn))
return 0;

bmp=(HBITMAP)LoadImage(hInst,file,IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if(!bmp)
return 0;

tempdc=CreateCompatibleDC(NULL);
SelectObject(tempdc,bmp);

BITMAPINFO bmi;
ZeroMemory(&bmi,sizeof(bmi));
bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biBitCount=0;
bmi.bmiHeader.biWidth=0;
bmi.bmiHeader.biHeight=0;
bmi.bmiHeader.biPlanes=0;
bmi.bmiHeader.biCompression=BI_RGB;
GetDIBits(tempdc,bmp,0,0,NULL,&bmi,DIB_RGB_COLORS);

bwidth=bmi.bmiHeader.biWidth;
bheight=bmi.bmiHeader.biHeight;


InvalidateRect(main,NULL,true);

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

DeleteObject(bmp);
DeleteDC(tempdc);

return 0;
}

Share this post


Link to post
Share on other sites
nevermind i just made it maximized
this took about 10 minutes to do
the only comments are where you can do the file stuff...


#include
#include



HINSTANCE hInst=NULL;
HWND main=NULL;
HBITMAP bmp=NULL;
HDC tempdc=NULL;

int bwidth,bheight;



LRESULT CALLBACK WindowProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_MOUSEMOVE:
{
if(LOWORD(lParam) {
char t[30];

sprintf(t,"Coordinates: (%d, %d)",LOWORD(lParam),HIWORD(lParam));
SetWindowText(main,t);
}
}
break;
case WM_LBUTTONDOWN:
{
int x=LOWORD(lParam);
int y=HIWORD(lParam);

// this x and y are thr coordiantes of the pixel on the bitmap
// do the file stuff here
}

case WM_CLOSE:
{
PostQuitMessage(0);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC dc=BeginPaint(hwnd,&ps);
if(tempdc)
{
BitBlt(dc,0,0,bwidth,bheight,tempdc,0,0,SRCCOPY);
}
EndPaint(hwnd,&ps);
}
break;
default:
{
return DefWindowProc(hwnd,message,wParam,lParam);
}
}

}




int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int iCmdShow)
{
MSG msg;
WNDCLASSEX wcex;
UINT width,height;

hInst=hInstance;

width=500;
height=400;

ZeroMemory((void *)&wcex,sizeof(wcex));

wcex.cbSize=sizeof(WNDCLASSEX);
wcex.hbrBackground=(HBRUSH)(COLOR_WINDOW);
wcex.hCursor=LoadCursor(NULL,IDC_CROSS);
wcex.hIcon=wcex.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
wcex.hInstance=hInstance;
wcex.lpfnWndProc=WindowProc;
wcex.style=CS_DBLCLKS;
wcex.lpszClassName="BitmapLoader Window";

if(!RegisterClassEx(&wcex))
{
return 0;
}

main=CreateWindowEx(0,"BitmapLoader Window","", WS_OVERLAPPEDWINDOW,50,50,width,height,NULL,NULL,hInstance,NULL);

if(!main)
{
return 0;
}

ShowWindow(main,SW_SHOWMAXIMIZED);


char file[MAX_PATH];
OPENFILENAME ofn;

ZeroMemory(&ofn, sizeof(OPENFILENAME));
ZeroMemory(file, sizeof(file));

ofn.lStructSize=sizeof(OPENFILENAME);
ofn.lpstrTitle="Choose File...";
ofn.hwndOwner=main;
ofn.lpstrFilter="Bitmaps (*.bmp)\0*.bmp\0All Files (*.*)\0*.*\0","bmp";
ofn.nFilterIndex=0;
ofn.lpstrDefExt="bmp";
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
ofn.lpstrFile = file;
ofn.nMaxFile = MAX_PATH;
//ofn.lpstrInitialDir = NULL;

if(!GetOpenFileName(&ofn))
return 0;

bmp=(HBITMAP)LoadImage(hInst,file,IMAGE_BITMAP,0,0,LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if(!bmp)
return 0;

tempdc=CreateCompatibleDC(NULL);
SelectObject(tempdc,bmp);

BITMAPINFO bmi;
ZeroMemory(&bmi,sizeof(bmi));
bmi.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biBitCount=0;
bmi.bmiHeader.biWidth=0;
bmi.bmiHeader.biHeight=0;
bmi.bmiHeader.biPlanes=0;
bmi.bmiHeader.biCompression=BI_RGB;
GetDIBits(tempdc,bmp,0,0,NULL,&bmi,DIB_RGB_COLORS);

bwidth=bmi.bmiHeader.biWidth;
bheight=bmi.bmiHeader.biHeight;


InvalidateRect(main,NULL,true);

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

DeleteObject(bmp);
DeleteDC(tempdc);

return 0;
}

Share this post


Link to post
Share on other sites
ok i forgot one thing - put a break right before the WM_CLOSE inside of the WindowProc function and it wont exit the app when the left button is clicked...

sorry about that... ;]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!