|
Ok, so how do I write a program to display the pixel values in the variable "image256[n]"? The values are stored in "image256[n]" but I don't know how to write a program to display them. Can you help?
|
|
|
|
|
I take it image256 is a BYTE* or unsigned char * ( they are the same thing ) ?
The easiest way to get direct access to the contents of a bitmap as a BYTE * is to create a DIBSECTION, ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_233i.asp[^] ) which will give you a HBITMAP you can pass to BitBlt or StretchBlt, and a pointer to the image bytes. This code:
BITMAP bitmap;
if (::GetObject(bm, sizeof(BITMAP), &bitmap))
{
hdr.AddImage(new CImage(bitmap, isGrey));
}
will fill a BITMAP structure with, among other things, the width, height and width in bytes of an image. To get to specific pixel value, you index your array by x*3 ( assuming a 24 bit image, 4 for a 32 bit image, and < 24 bits it just won't work ) + y * bm.WidthBytes. Then you have three bytes to read, they are the blue, green and red values.
So, if you create a DIBSECTION that is the same size as your image, then you can step through and use memcpy to copy the data in, one row at a time. Bitmaps are padded to be word aligned, which is why you have the WidthBytes variable, it can be more than width*3. Your data may not be the same, otherwise I'd say just copy the whole lot in at once.
Hopefully that points you in the right direction. So your library is flattening the DICOM image and giving it to you as a BYTE * then ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
This is how the program looks like. I need to write in that part of the program to display the black and white pixels when I run the program. I think this is where the pixels are stored. Please advise. Thank you.
void CMediVisionView::ReDraw()
{
int row, col;
int p, q, n;
int cx_position[6], cy_position[6];
unsigned int data;
BITMAPINFOHEADER infoHeader;
infoHeader.biSize = sizeof(BITMAPINFOHEADER);
infoHeader.biWidth = n_cols;
infoHeader.biHeight = n_rows;
infoHeader.biPlanes=1;
infoHeader.biBitCount= 24;
infoHeader.biCompression=0;
infoHeader.biSizeImage=0;
infoHeader.biXPelsPerMeter=0;
infoHeader.biYPelsPerMeter=0;
infoHeader.biClrUsed=0;
infoHeader.biClrImportant=0;
int xSize=::GetSystemMetrics(SM_CXSCREEN)-80;
int ySize=::GetSystemMetrics(SM_CYSCREEN);
CClientDC ClientDC(this); // Draw the Frame Lines first
FrameLines(&ClientDC);
if (n_rows== 256 && multiple_open) {
if(image_no == 1) {
cx_position[1] = posx512-4;
cy_position[1] = posy512;
}
else if(image_no == 2) {
cx_position[1] = posx512-4;
cy_position[1] = posy512;
cx_position[2] = posx512-4 + 256 + 3;
cy_position[2] = posy512;
}
else if(image_no == 3) {
cx_position[1] = posx512-4;
cy_position[1] = posy512;
cx_position[2] = posx512-4 + 256 + 3;
cy_position[2] = posy512;
cx_position[3] = posx512-4;
cy_position[3] = posy512 + 256 + 3;
}
else if(image_no == 4) {
cx_position[1] = posx512-4;
cy_position[1] = posy512;
cx_position[2] = posx512-4 + 256 + 3;
cy_position[2] = posy512;
cx_position[3] = posx512-4;
cy_position[3] = posy512 + 256 + 3;
cx_position[4] = posx512-4 + 256 + 3;
cy_position[4] = posy512 + 256 + 3;
}
for(int s=1;s<=image_no;s++) {
n = 0;
for(int p=0;p
|
|
|
|
|
sclh wrote:
StretchDIBits
This means you're using a DIB - this function is what draws it.
This code is ugly, it was obviously written by a C programmer who never learned C++ properly.
sclh wrote:
for(int s=1;s<=image_no;s++) {
n = 0;
for(int p=0;p for(int q=0;q data = image[s][n];
if (data <= 0) {
argb256Pixels[p][q] = (unsigned int)(0 | 0 | 0 | 0);
}
else {
argb256Pixels[p][q] = (unsigned int)(data<<24 | data<<16 | data<<8 | data);
}
n++;
}
}
This code ( which has been mangled because you didn't check 'Do not treat <'s as HTML tags') is copying the pixel values.
sclh wrote:
argbPixelsPtr = (unsigned char *) argb256Pixels;
rgbPixelsPtr = (unsigned char *) rgb256Pixels;
for (row=0; row for(col=0; col *rgbPixelsPtr++ = *argbPixelsPtr++;
*rgbPixelsPtr++ = *argbPixelsPtr++;
*rgbPixelsPtr++ = *argbPixelsPtr++;
argbPixelsPtr++;
}
}
This bit of code is copying from one image to another, one byte at a time. It's going from a 24 bit image to a 32 bit image. Goodness knows why.
Really, it seems to me like you have no idea what's happening here. Do your fellow students share your dismay ? If so, complain to the school that your teacher is no good. Assuming he wrote this code, he's definately not a person to be teaching C++.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi, does that means the whole program should be using DIB instead of MFC C++? The part on converting DICOM to raw format?
|
|
|
|
|
Hello, I am relatively new to the visual studio.net platform but not programming itself, anyways, my question is, I just downloaded the directX SDK 9.0 and I want to know how to implement them in my applications, and please don't tell me that the installation does it automatically because it doesnt, at least not on my comp, anyways, any and all help will be appreciated, thx.
|
|
|
|
|
The installation does it automatically
Seriously, make sure VS.NET is closed while you install the SDK, and you will have DX options in your new project options. If 9.0 supports managed code, the install does not without a command line switch when you run it - I think it's -manageddx, but that's from very vague memory.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I looking through the projects options but im not seeing it, can you tell me the exact location of the DX project template?
|
|
|
|
|
I don't seem to have it installed anymore. Did you take my advice, uninstall, close the IDE and reinstall ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
As a new Visual C++ programmer, I keep seeing examples of WriteLine with an 'S' preceding a literal string. What's that for?
|
|
|
|
|
There are many ways for a string to be represented in memory, I've only seen L next to a string to make it wide, but S would have to do something similar.
It's kind of hard to google for S
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I have a binary file with data(short), how can I cast it into a text file? Using CFile to read/write
thanks
|
|
|
|
|
heng0987 wrote:
I have a binary file with data(short), how can I cast it into a text file?
Read the numbers in, and then write them out to a new file as numbers. I'm not sure how to do that using CFile, but with an IOStream you could just pass them in.
CFile is really crap BTW, you should look into iostreams as a far better alternative.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
|
I am totally new to .NET. Here ia a stupid question:
why I can not include <ofsteam> and <ifstea> ? I have the full .NET 2003 package on my machine.
thanks
|
|
|
|
|
I wrote a console application in Windows XP Visual C++ 6.0 and sent it to someone running Windows 2000 but it wouldn't run. An error box poped up saying The dynamix link library MFC4rD.DLL could not be found in ...
Is this a known problem? Is there any hope for me?
|
|
|
|
|
You sent the person a debug build (which requires MFC42D.dll). Rebuild the application in release mode and ship that version (which will require MFC42.dll, which in all likelihood already exists on their system).
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
An an aside to Ravi's recommendation, if you switch the project to use MFC in a static library, you won't need to ship any MFC DLLs at all.
|
|
|
|
|
Thank you both for your help.
|
|
|
|
|
Hi there,
I need to delete the Options menu during run-time. Currently it deletes it when the application first starts up. Then as I open up other CMultiDocTemplate windows, it reappears. These are the two functions I have in the CMainFrame class. I called the OnChangeFileMenu() function within the application class in InitInstance(). I thought that would do the trick but somehow it reappears as I open up other modal windows.
void CMainFrame::OnChangeFileMenu()
{
CWnd* pMain = AfxGetMainWnd();
// Get the menu from the application window.
CMenu* mmenu = pMain->GetMenu();
int pos = FindMenuItem(mmenu, "&Options");
if (pos > -1)
mmenu->RemoveMenu(pos, MF_BYPOSITION);
pMain->DrawMenuBar();
}
int CMainFrame::FindMenuItem(CMenu *menu, LPCTSTR menustr)
{
ASSERT(menu);
ASSERT(::IsMenu(menu->GetSafeHmenu()));
int count = menu->GetMenuItemCount();
for (int i = 0; i < count; i++)
{
CString str;
if (menu->GetMenuString(i, str, MF_BYPOSITION) &&
(strcmp(str, menustr) == 0))
return i;
}
return -1;
}
Besides inserting the below code in InitInstance, I also included it in the document view class's OnInitialUpdate:
// Get MDI Frame window
CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
#ifdef MODE_1
pMainFrame->OnChangeFileMenu();
#endif
That did the trick for only one document view class but not others. It does not detect the presence of the menu when it's called yet it reappears afterwards. How can I remove it completely without having to insert the above code in numerous places. It should have taken care of it in InitInstance(). Thanks.
|
|
|
|
|
I had a similar issue, but I took care of it by only having one menu. When no document is loaded,
a lot of the menu items are gray... But my application only deals with one type of document, so
that solution may not be suitable for you.
Iain.
|
|
|
|
|
I was trying to avoid having to create a second menu with the item removed but in the end I chose that route. So in InitInstance, one of the menus will appear according to my criteria. Thanks for responding though.
|
|
|
|
|
I am trying to hook to a process.
i use "CreateProcess" method to create process as WinWord.exe, MSPaint.exe
etc....
then i use a hooking (using SetWindowsHookEx method) with the call
WH_CBT and in the proc i try to catch HCBT_CREATEWND and see if it is the main window.....
this all means that i need to hook the creation of the process i have just created and retrieve a handle HWND to its main window
it works ok with MSPaint but for word and excel and power point for example, it don't work at all....it seems that the hook occurs right after the main window was already created that is why the message WM_CREATE never cought....
can any1 help?
am i doing it wrong? is there a better way?
10x in advanced
Yaron
|
|
|
|
|
Im using MFC to make dailog based program.
I have one button that will change my start button text to "TEST" after click.
my program crash after I clicked on the button
here is the code for the button.
void CStart_Button_ChangerDlg::OnText()
{
HWND starthandle;
CWnd StartButton;
CWnd* Window = CWnd::FindWindow("Shell_TrayWnd","");
starthandle = FindWindowEx(NULL,NULL,"Button","");
StartButton.m_hWnd=starthandle;
StartButton.SetWindowText("TEST");
StartButton.SendMessage(WM_SETTEXT,0,0);
//SendMessage (StartButton, WM_SETTEXT, 0);
}
|
|
|
|
|