|
Thanks for your answer,
I'm using MDI and till now (at the beginning) I have already about 10 DocTemplates. So I hoped, I can make the graphic (for each of this templates) without making a new one.
But regardless of this your answer helped me. I recogniced, that I have only to make a new View (and use the old Doc).
Thanks, Gerhard
|
|
|
|
|
Hello all,
i'm trying to display a Bitmap in a Picture Control. The picture is captured by a CMOS camera (gray), and all i have is a pointer to the image in the Framegrabber buffer. The problem is that i don't have a real bitmap in that buffer, just an array with pixel values. The technical support of the Framgrabber producer couldn't help me till now and i'm still waiting for thier reply . I was trying to create a Bitmap manualy and fill in all the needed structures like BITMAPINFO and so on but nothing worked. Can you tell me how to construct a bitmap from an pixelarray, just knowing the lenght, width and that's it is gray scale picture.
I would be very greatfull for any kind of help!
I wish you a nice Weekend
im79
|
|
|
|
|
Gray as in 8-bits per pixel? Did you set up the color table? Show how you're calling CreateDIBitmap and your input values (BITMAPINFO).
|
|
|
|
|
Hello all, hello hrfy and thanks for your answer
Yes it is 8-bits per pixel. I didn't set the color table. I just called CreateBitmap or DIBitmap passing width, length, the pointer to the pixel array and so on. I as i explaind in my first posting, i don't have a BITMAPINFO, can make one manualy?
I tried manythings but nothing worked. I'm new to windows programming and MFC.
I'm not at work now, so i don't have the source code here right now.
Eventhough i cann't provide enough info, i hope u can still help me on this one
Kind regards and thanks again ,
im79
|
|
|
|
|
im79 wrote: i don't have a BITMAPINFO, can make one manualy?
If you know what kind of data is in the pixel array, you should have no problem populating the header.
I've just written and tested this by generating a grayscale gradient and it works.
HBITMAP CreateGrayscaleBitmap(int nWidth, int nHeight, LPBYTE pData)
{
BITMAPINFO *pbmi = (BITMAPINFO*) new BYTE[sizeof(BITMAPINFO) + (sizeof(RGBQUAD) * 256)];
ZeroMemory(pbmi, sizeof(BITMAPINFO));
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
pbmi->bmiHeader.biWidth = nWidth;
pbmi->bmiHeader.biHeight = -nHeight;
pbmi->bmiHeader.biPlanes = 1;
pbmi->bmiHeader.biBitCount = 8;
pbmi->bmiHeader.biCompression = BI_RGB;
pbmi->bmiHeader.biSizeImage = nWidth * nHeight;
RGBQUAD *pColors = pbmi->bmiColors;
for(int i = 0; i < 256; i++)
{
pColors->rgbBlue = i;
pColors->rgbGreen = i;
pColors->rgbRed = i;
pColors->rgbReserved = 0;
pColors++;
}
CWindowDC dc(NULL);
HBITMAP hBitmap = CreateDIBitmap(dc, &pbmi->bmiHeader, CBM_INIT, pData, pbmi, DIB_RGB_COLORS);
delete pbmi;
return hBitmap;
}
This is for a top-down bitmap. If your image is flipped, remove the negative sign in front of the height.
|
|
|
|
|
Hi, i've tried your code in my appicaltion and have another problem now . I need a CBitmap object, so i tried the following:
<br />
CDC *pDC = GetDC();<br />
CBitmap* myBitmap;<br />
<br />
myBitmap = CBitmap::FromHandle(hBitmap);<br />
myBitmap->CreateCompatibleBitmap(pDC, m_iWidth, m_iHeight);<br />
myBitmap->LoadBitmap(IDC_STATIC_PICTURE);
I get an Unhandled exception in wingdi.cpp line 1102:
<br />
BOOL CGdiObject::Attach(HGDIOBJ hObject)<br />
{<br />
ASSERT(m_hObject == NULL);
if (hObject == NULL)<br />
return FALSE;<br />
CHandleMap* pMap = afxMapHGDIOBJ(TRUE);<br />
ASSERT(pMap != NULL);<br />
pMap->SetPermanent(m_hObject = hObject, this);<br />
return TRUE;<br />
}<br />
This is the call stack:
>mfc71d.dll!CGdiObject::Attach(void * hObject=0x0305061d) Line 1102 + 0x1c C++
mfc71d.dll!CBitmap::CreateCompatibleBitmap(CDC * pDC=0x00816af4, int nWidth=400, int nHeight=400) Line 217 + 0x25 C++
I hope you can help me again here
im79
|
|
|
|
|
im79 wrote: myBitmap->CreateCompatibleBitmap(pDC, m_iWidth, m_iHeight);
What are you trying to do here?
im79 wrote: myBitmap->LoadBitmap(IDC_STATIC_PICTURE);//picture control in my dialog
The CBitmap::LoadBitmap function is used to load an image into the bitmap, not set an image into a picture control...
|
|
|
|
|
hfry wrote: im79 wrote:
myBitmap->CreateCompatibleBitmap(pDC, m_iWidth, m_iHeight);
What are you trying to do here?
I thought that i have to convert the DIB to a DDB Bitmap, so i guess that's wrong
I just want to display the Bitmap in a picture control, but it's not as easy as i thought
hfry wrote: The CBitmap::LoadBitmap function is used to load an image into the bitmap, not set an image into a picture control...
Yes that's stupid, I should have read the MSDN manuals
|
|
|
|
|
im79 wrote: it's not as easy as i thought
It is actually.
CStatic *picture = (CStatic*) GetDlgItem(IDC_STATIC_PICTURE);
picture->SetBitmap(hBitmap);
Make sure the static control's type is actually set to Bitmap.
|
|
|
|
|
Hi hfry
It's working
Thank you very much
|
|
|
|
|
Hi
i need your (or any one's) help again
I'm trying for long time to change this code in order to make an 8Bit color Bitmap but it's not working
I'll be greatfull for any help!
|
|
|
|
|
Hi,
RGBQUAD *pColors = pbmi->bmiColors;
for(int i = 0; i < 256; i++)
{
pColors->rgbBlue = i;
pColors->rgbGreen = i;
pColors->rgbRed = i;
pColors->rgbReserved = 0;
pColors++;
}
The code snippet above is setting the color table. In your previous question, you wanted it grayscale so the color table so I set it up as such. If you want it to be color you need to setup the appropriate color table that your 8-bit data maps to.
Regards,
Justin Tay
|
|
|
|
|
I have two very simple classes as shown below. In my application code, I want to test the
condition of the object - is it valid? But, VC++ tells me :
"error C2248: 'IsValid' : cannot access public member declared in class 'CBaseFile'"
Why? Why? For goodness' sake, why? Is it not declared public? It looks like it, it even tells
me it is public. What obvious goof don't I see?
{
// app code snippet:
CSpecialFile *pSpecialFile = new CSpecialFile("a filename");
if (!pSpecialFile->IsValid()) AfxMessageBox("Oh no!!! Mr. Bill...");
}
class CBaseFile
{
public:
CBaseFile(CString sFilename);
virtual ~CBaseFile();
bool IsValid();
private:
bool m_bIsValid; // true if no problems encountered;
};
Then I inherit from it...
class CSpecialFile: CBaseFile
{
public:
CSpecialFile(CString sFilename);
virtual ~CSpecialFile();
// more methods specific to special file object go here....
};
Charlie Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
My son's PDA is an M249 SAW.
|
|
|
|
|
You need this:
class CSpecialFile: public CBaseFile
0 bottles of beer on the wall, 0 bottles of beer, you take 1 down, pass it around, 4294967295 bottles of beer on the wall.
Awasu 2.2.2 [^]: A free RSS/Atom feed reader with support for Code Project.
|
|
|
|
|
doh! insert sound of hand slapping forehead!
btw, love your sig...
Charlie Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
My son's PDA is an M249 SAW.
|
|
|
|
|
|
Hie,
i just downloaded VC 2005 express.I opened an old VC 6 project that was written in the C language.When i tried building this in VC 2005 EXPRESS.. it gives me a whole Plethora of errors .Is the C language no more supported by VC express.Also i installed Microsoft Visual Studio .NET 2003.here VC supports the c language BUT does'nt support XP style.Where as VC 2005 express has a really good XP look .. i mean even the menus have a blue gradient on them.My problem is i NEED TO HAVE A VERSION THAT SUPPORTS XP STYLE AND THE C PROGRAMMING LANGUAGE.i only know C.Also i would really appreciate it if someone pointed me to a good
e-book on using VC with C++ NO MFC! .. i gonna start C++ soon!;P
|
|
|
|
|
|
Many of the old C APIs have been deprecated. I imagine that is the majority of your errors/warnings. You can turn that off using a compiler switch (you'll have to look that up as I don't have VS available at the moment).
These aren't e-books, but they are perhaps the best books you'll find for Win32 programming without MFC:
Programming Windows by Charles Petzold
Programming Applications for Microsoft Windows by Jeffrey Richter
Note: get the older editions as the newer ones have been written with C# (which was a mistake IMHO).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: Many of the old C APIs have been deprecated. I imagine that is the majority of your errors/warnings. You can turn that off using a compiler switch (you'll have to look that up as I don't have VS available at the moment).
Hi , its been a while. Yea , i got petzolds book and other books too and learnt C# , and its awesome!! Way better than win32 , i can build more powerful apps way faster! Without losing my head! (thats for anyone else doing win32)
About my problem , it seems the vc express does'nt come with the PSDK.
Look at this[^]
Hope that helped someone.
Gideon
|
|
|
|
|
Is there any way to trick the C++ compiler and get the value of a non-static member variable from a static method.
e.g.
class CDummy
{
public:
int m_myInt;
static void dummy();
};
void CDummy::dummy()
{
int x = m_myInt; ????
}
Thanks!
modified 9-Mar-17 17:16pm.
|
|
|
|
|
Not without passing a reference to the instance of your class.
I Dream of Absolute Zero
|
|
|
|
|
Yes ... its called make a non-static version of the method:
class CDummy
{
public:
int m_myInt;
static void dummy(const CDummy& dum);
void dummy() const;
};
void CDummy::dummy(const CDummy& dum)
{
dum.dummy();
}
void CDummy::dummy() const
{
int x = m_myInt;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi,
I have outlook configured on my machine.
I need to send data (textual) to one email contact only .
Means I will have some text ready at some time interval and every tiem I read the data the data should go as email to this address using my outlook config.
How can I achieve this.
pathak
|
|
|
|
|
See here and here for examples of sending e-mail.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|