Using visual C++ to create a simple image and masker tool kit

When we meet a semantic segmentation task, like medical image segmentation, we usually using a software called ‘snap-itk’. It has a lot of function to help users mark a label of image, saving images and its segmentation with file format of NII. So it’s really powerful but there is a disadvantage on it for the file format NII can not be shown as a brief thumbnail on no matter Windows nor Linux systems. Here I write a simple image and mask tool kit using visual C++, mainly using the transparent property of Class Window on Windows NT system. OK, let’s begin our journey.

 

For the super large thumbnail of images on windows having meeting my scanning needs of images and maskers, so the rest of the task is just doing a tool that can cover the masker upon the image. Following the principle of simple and brief, i decide to design a image reader and a masker reader. Drag the image onto the image reader to open a image and with the same operation on masker it will open right on the top of image with a fully transparency of front ground label and a half transparency of background.

 

A image reader is easy to create. Just follow the visual studio windows program wizard. And in the main function

//

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,

                     _In_opt_ HINSTANCE hPrevInstance,

                     _In_ LPWSTR    lpCmdLine,

                     _In_ int       nCmdShow)

//

I take advantage of  lpCmdLine to find the dragged image path. Like this in function:

//

p = (WCHAR*)lpCmdLine;

//

And p is a global point variable to save the image path information:

//

WCHAR *p = NULL;

//

Then we can reader the target image in windows message call back processing

Function like this:

//

    case WM_PAINT:

        {

PAINTSTRUCT ps;

HDC hdc = BeginPaint(hWnd, &ps);

 

memdc = CreateCompatibleDC(hdc);  //获取内存设备环境

CImage image;

image.Load(p);

//根据image获得hBitmapt  

hbg = image.Detach();

SelectObject(memdc, hbg);

GetObject(hbg, sizeof(BITMAP), (LPVOID)&bm);//获取位图尺寸

BitBlt(ps.hdc, 0, 0, bm.bmWidth, bm.bmHeight, memdc, 0, 0, SRCCOPY);

 

EndPaint(hWnd, &ps);

        }

        break;

//

Here we finish our image reader designing, It’s simple. isn’t it?

 

Secondly phase, designing a mask reader. We hope when it opened, it’s initial position and size is right coincide to the image. So first we design a same image reader as presented upon, and then we set it always on the top and transparent, like this:

//

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED | WS_EX_TRANSPARENT);

 

RECT rc;

GetWindowRect(GetDesktopWindow(), &rc);

::SetLayeredWindowAttributes(hWnd, RGB(255, 255, 255), 200, LWA_ALPHA | LWA_COLORKEY);

::SetWindowPos(hWnd, HWND_TOPMOST, 300, 300, 512, 512, 0);

//

On instance initialize function.

 

The final result presented followed:

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值