|
Hi,
i tried to modify the codes to display only gray scale image and aslo the original image.So far my program just display a blank bitmap.Anyone can please help me.
void CMy2ndtryView::OnDraw(CDC* pDC)
{
CMy2ndtryDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CDC MemDC;
MemDC.CreateCompatibleDC (NULL);
MemDC.SelectObject (&m_Bitmap);
pDC->BitBlt
(20,
20,
m_BitmapWidth,
m_BitmapHeight,
&MemDC,
0,
0,
SRCCOPY);
CDC resultDC;
CBitmap m_result;
m_result.CreateCompatibleBitmap(pDC,m_BitmapWidth,m_BitmapHeight);
resultDC.CreateCompatibleDC (NULL);
resultDC.SelectObject (&m_Bitmap);
for( int y = 0; y < m_BitmapHeight ; y++ )
{
for( int x = 0; x < m_BitmapWidth ; x++ )
{
//set pixel to color returned by convolve
resultDC.SetPixel(x,y,Convolve(&MemDC,x,y,kernel));
}
}
//Display Result
pDC->BitBlt
(300,
20,
m_BitmapWidth,
m_BitmapHeight,
&resultDC,
0,
0,
SRCCOPY);
}
COLORREF CMy2ndtryView::Convolve(CDC *pDC, int sourcex, int sourcey, float kernel[][3])
{
float rSum = 0, gSum = 0, bSum = 0, kSum = 0;
float grayscale =0;
COLORREF clrReturn = RGB(0,0,0);
for (int i=0; i <= 2; i++)//loop through rows
{
for (int j=0; j <= 2; j++)//loop through columns
{
COLORREF tmpPixel = pDC->GetPixel(sourcex+(i-(2>>1)),sourcey+(j-(2>>1)));
float fKernel = kernel[i][j];
rSum += (GetRValue(tmpPixel)*fKernel);
gSum += (GetGValue(tmpPixel)*fKernel);
bSum += (GetBValue(tmpPixel)*fKernel);
kSum += fKernel;
}
}
if (kSum <= 0)
kSum = 1;
rSum/=kSum;
gSum/=kSum;
bSum/=kSum;
if (rSum > 255)
rSum = 255;
else if (rSum < 0)
rSum = 0;
if (gSum > 255)
gSum = 255;
else if (gSum < 0)
gSum = 0;
if (bSum > 255)
bSum = 255;
else if (bSum < 0)
bSum = 0;
grayscale=0.299*rSum + 0.587*gSum + 0.114*bSum;
rSum=grayscale;
gSum=grayscale;
bSum=grayscale;
clrReturn = RGB(rSum,gSum,bSum);
return clrReturn;
}
Is there something with my formula for grayscale?
grayscale=0.299*rSum + 0.587*gSum + 0.114*bSum;
|
|
|
|
|
Is there a standard way to attach a description to the data being dragged. I require this as the name of the data being dragged can include characters that are invalid in filename field of the FILEGROUPDESCRIPTOR structure (such as slashes or question marks) and I would like to be able to extract the description when the data is dropped. It would appear Outlook just replaces the invalid characters with blanks when creating the filename and then specifies the full name (subject text) as an additional Object Descriptor format.
Systems AXIS Ltd - Software for Business ...
|
|
|
|
|
hi,
i'm writing a (legacy, non-MFC) dll and there might get an exception thrown in there. it is caught in the exe-file that uses that dll.
dll:
throw new CSomeException();
exe:
catch (CSomeException *e)<br />
{<br />
e->SomeFunction();
delete e;
}
the delete-call crashes because the object is not a valid *local* heap-pointer.
stepping in dbgheap.c reveales the following passage
<br />
_ASSERTE(_CrtIsValidHeapPointer(pUserData));
so, finally. how am i supposed to handle this? i mean throwing an exception in a library isn't that uncommon, is it?
:wq
|
|
|
|
|
I bet at least one of your modules (exe or dll) has CRT statically linked. That means that one instance of CRT is allocating the memory and another one tries to release it ... BANG!
A solution is to link all your modules dinamically (option /MD) against CRT. This way they will share the same CRT instance, and you should be able to allocate memory in one module and release it in another.
Either that, or make sure that each module cleans its own memory.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
bingo! the DLL was set to /MT[d] - I changed that to /MD[d] and it seems to work (just gave it a quick shot)
thx, man!
:wq
|
|
|
|
|
If my memory serves me right, an object new'd by a regular MFC DLL must be destructed by that DLL. An object new'd by an extension MFC DLL can be destructed by the client. See this[^] article.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
i am reading the first 14 bytes of a bitmap into a struct like this:
struct bmfh
{
unsigned short int bfType;
unsigned long int bfSize;
unsigned short int bfReserved1, bfReserved2;
unsigned long int bfOffBits;
};
and the results come out like this:
type: BM
size: 5
reserved1: 0
reserved2: 1078
bit offset: 3452764160
surely the size and offset cant be correct, does anyone know what i'm doing wrong? other bitmaps give similar values.
|
|
|
|
|
what are the first 14 bytes of the file? (you look at it in VC, if you open it as a "binary" file)
Software | Cleek
|
|
|
|
|
aha, i didnt know you could do that in vc++..
42 4D 9A 31 08 00 00 00 00 00 36 04 00 00
|
|
|
|
|
any reason you're not using MS's BITMAPFILEHEADER struct?
when i do this:
<br />
BYTE buf[14] = {0x42 ,0x4D ,0x9A ,0x31 ,0x08 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x36 ,0x04 ,0x00 ,0x00 };<br />
BITMAPFILEHEADER *b = (BITMAPFILEHEADER *)buf;<br />
the values look fine:
bfType: 19778 ('BM')
bfSize: 536986
bfReserved1: 0
bfReserved2: 0
bfOffBits: 1078
-c
Software | Cleek
|
|
|
|
|
hmm, thats what should happen with mine. i'm just using my own struct to better understand the file format and stuff. as far as i can see, mine is identical to the microsoft one..
|
|
|
|
|
are you using the 'pack' pragmas to ensure the members of your struct are aligned correctly?
ie.:
<br />
#pragma pack(2)<br />
typedef struct tagBITMAPFILEHEADER {<br />
WORD bfType;<br />
DWORD bfSize;<br />
WORD bfReserved1;<br />
WORD bfReserved2;<br />
DWORD bfOffBits;<br />
} BITMAPFILEHEADER, FAR *LPBITMAPFILEHEADER, *PBITMAPFILEHEADER;<br />
#pragma pack()<br />
-c
Software | Cleek
|
|
|
|
|
that works perfectly now, could you explain what this pragma pack nonsense is all about and what it does?
thanks very much for your help.
|
|
|
|
|
#pragma pack(n) tells the compiler to arrange your structs so that the struct members each start on addresses that are multiples of 'n'. your problem was that the members of the struct weren't in the right places to be filled by your file read function, because they weren't aligned the way you assumed they were.
the default packing size is 8; so, in effect, each member of a struct takes a minimum of 8 bytes. you can change this on a project-wide level in Project / Settings / C/C++ / Code Generation, or on specific structs using the #pragma pack constructs.
this is one of those things we all have to learn the hard way, since it's not exactly well-advertized
Software | Cleek
|
|
|
|
|
This is what the documentation says but in practice it doesn't seem to work that way. Data structure members get packed to offset that corresponds to the size of their type ie., shorts to a two-byte boundary, ints to a four-byte boundary.
Here is a sample program and its output :
<br />
#include "stdafx.h"<br />
<br />
typedef struct<br />
{<br />
unsigned short int bfType; <br />
unsigned long int bfSize; <br />
unsigned short int bfReserved1;<br />
unsigned short int bfReserved2;<br />
unsigned long int bfOffBits; <br />
} BMFH;<br />
<br />
<br />
int main( int argc, char* argv[] )<br />
{<br />
printf( "sizeof BMFH is %d bytes\n", sizeof( BMFH ) );<br />
printf( "offset of bfSize is %2d\n", offsetof( BMFH, bfSize ) );<br />
printf( "offset of bfReserved1 is %2d\n", offsetof( BMFH, bfReserved1 ) );<br />
printf( "offset of bfReserved2 is %2d\n", offsetof( BMFH, bfReserved2 ) );<br />
printf( "offset of bfOffBits is %2d\n", offsetof( BMFH, bfOffBits ) );<br />
return 0;<br />
}<br />
sizeof BMFH is 16 bytes
offset of bfSize is 4
offset of bfReserved1 is 8
offset of bfReserved2 is 10
offset of bfOffBits is 12
__________________________________________
a two cent stamp short of going postal.
|
|
|
|
|
I want to change the default settings, to be precise the color of the buttons and the message background that they appear. I want the background and the button to have to different colors. I have research the Internet and have found no answer. I’m programming in Microsoft Visual C++ 6.0. Thank you in advance.
YaX
|
|
|
|
|
Are you talking about the Appearance tab of the Display Properties dialog?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Thanks Dave... I was thinking more of hard coding the color... but yes i'm talking about the appearance tab... if i change the colors of the 3-d object it changes both the button and the window color. I only want to change the color of the button. Do you have any Suggestions on how i could possible hard coded.
YaX
|
|
|
|
|
To change the color of a button, I believe you need to override the OnCtlColor() method of the dialog class.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
HI,
There r examples on CP. abut Skin thay use BMPs for skin
I want to use GIF or PNG (fire works) files
Like animated Skins on dialogs.
How can i do this.
any link , example etc
thanx
Regards.
|
|
|
|
|
have a browse through the dialog[^] section of CP. There are a few articles there dealing with skinable dialogs.
I Dream of Absolute Zero
|
|
|
|
|
There r many but use BMP Images/files.
I want to Use GIF and PNG images.
any help in this regard.
thanx
Regards.
|
|
|
|
|
hello everyone..
this is my first post in this forum and actually it's a question about DLL's:
I made a *.cpp file with the following
#include <afx.h><br />
#include <Mmsystem.h><br />
<br />
LPCSTR _stdcall OpenSound (LPCSTR lpfile){<br />
CString str = lpfile;<br />
MCIERROR dwRet;<br />
<br />
str = "open \"" + str + "\" alias jack";<br />
<br />
dwRet = mciSendString(str,NULL,0,NULL);<br />
if (dwRet)<br />
MessageBox(NULL,"Fail to open","Hello!",0);<br />
else<br />
if (mciSendString("close all",NULL,0,NULL))<br />
MessageBox(NULL,"Fail to close","Hello!",0);<br />
<br />
<br />
return lpfile;<br />
}
and ofcourse I made a *.def file for it..
the problem is that the final DLL is TOO big ((80.0 kb in Release and 1.23 mb in Debug))
I made a dll in vb which contains a lot of functions and the size of it was about 60.0 kb..
so is there a way to minimize the DLL made by c++..
|
|
|
|
|
80kb doesn't sound too large to me.
What version of CString are you using?
Is it the MFC or ATL version? Are you statically linking or dynaminc link ATL/MFC
What kind of compiler optimisation settings are you using?
Michael
CP Blog [^]
|
|
|
|
|
I'm using the MFC and I don't know how to know if it's statically or dynamically!!
also I don't know about the optimisation thing..
actually I'm a very newb to these stuff..
|
|
|
|