|
Hi,
hm ... check if all pointers are initialized
-----------
Mila
|
|
|
|
|
Require neat code review .
Refer this[^] article for better understanding.
|
|
|
|
|
As stated by Mila025 maybe an initialization problem. uninitialized vars gets zeroes in debug mode, but gets garbage in release one. For instance if you pass a struct to a Windows API, and you not initialize it, then maybe zeroes will be harmless, while garbage will make your program crash.
hope that helps
-- modified at 6:11 Friday 29th December, 2006
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Which is the error you getting ?
If u can Dream... U can do it
|
|
|
|
|
This is something very common,
You should look:
- If your pointers are correctly initialized.
- If you are using some dll's or specific external files or programs, you should take a look if they are placed in the debug and in the release folders. (think that if somewhere of the app you are using something like GetAppPath() then you can have some problems related to files that could be in the debug folder but not in teh release one.
- Look in the project options that you have the same configuration in the DEBUG than in the RELEASE.
- There can be several other things, this can be hard to find out what is happening, but if you cannot find the problem you can always try to use MessageBoxes spreaded from the beggining to the end in order to be able to give us more information on what's happening, where and when.
Hope this helps even if it is not a very good answer.
|
|
|
|
|
Hi,
i load bitmap data by using fopen/fread standard c functions. after reading the whole image in a buffer i calculate bitmapfileheader and bitmapinfoheader from that buffer that is ok without any problem. now i want to draw this image but i am unable to draw it. i use CBitmap CreateBitmap function to create image from this data but when i draw the image it is in black color. here is code how i try to do it.
file = fopen("test.bmp", "rb");
fseek(file, SEEK_END, SEEK_END);
nSize = ftell(file);
byBmp = new BYTE[nSize];
fseek(file, SEEK_SET, SEEK_SET);
memset(byBmp, 0, nSize);
fread(byBmp,nSize, 1, file);
BITMAPFILEHEADER bmfh;
memcpy(&bmfh, byBmp, sizeof(bmfh));
BITMAPINFOHEADER bmih;
memcpy(&bmih, byBmp + sizeof(bmfh), sizeof(bmih));
BOOL b = m_bmpBackImage.CreateBitmap(bmih.biWidth, bmih.biHeight, bmih.biPlanes, bmih.biBitCount, NULL);
m_bmpBackImage.SetBitmapBits(bmih.biWidth*bmih.biHeight, byBmp + bmfh.bfOffBits);
somewhere onpaint event i try to draw this bitmap but end result is black image.
please help how can i create image from a buffer data. is there any thing that i am missing.
thanks in advance.
Omar Lodhi
|
|
|
|
|
There is a MSDN sample demonstrating the usage of bitmaps from files.
I forgot the sample name, but I am pretty sure you can search for "SaveBmp".
Anyway, I think you are doing something wrong not at bitmap loading, but bitmap drawing.
Try to use the standard steps:
CreateCompatibleDC (--> memory DC)
CreateCompatibleBitmap (--> memory bitmap)
select memory bitmap in memory DC
draw in memory bitmap
BitBlt from memory DC into window DC
destroy/release all (HBITMAP, HDC etc)
|
|
|
|
|
Hi,
thanks for your help, i have tried to search from msdn but no result i will try it again. here is the code i try to draw bitmap.
dcMemBkImage.CreateCompatibleDC(pDC);
//this image was previously created
dcMemBkImage.SelectObject(&m_bmpBackImage);
GetObject(m_bmpBackImage,sizeof(bitmap),&bitmap);
pDC->BitBlt(m_nLeft, m_nTop, bitmap.bmWidth, bitmap.bmHeight, &dcMemBkImage, 0, 0, SRCCOPY);
dcMemBkImage.DeleteDC();
please guide me if there is some error in this code.
thanks,
omar lodhi
|
|
|
|
|
m_bmpBackImage should be a result of CreateCompatibleBitmap.
(I don't know if works with a cached CBitmap variable).
After this, try to use SetBitmapDimension to set the bitmap size, load data from bitmap file, and call SetDIBits to set bitmap data. Now you should have the memory bitmap completed.
(I suppose this is what GetObject does?)
Finally, call BitBlt to transfer the bitmap from memory into DC.
|
|
|
|
|
Hi,
i have little bit confusion like u said to create using CreateCompatibleBitmap.
Is it necessary to create the bitmap this way?
I am creating the bitmap as i mentioned in the first post like this
nWidth = bmih.biWidth*3;
if(bmih.biWidth*3%4 != 0)
{
nWidth = bmih.biWidth*3 + 4-(bmih.biWidth*3%4);
}
BOOL b = m_bmpBackImage.CreateBitmap(bmih.biWidth, bmih.biHeight, bmih.biPlanes, bmih.biBitCount, NULL);
m_bmpBackImage.SetBitmapBits(nWidth*bmih.biHeight, byBmp + bmfh.bfOffBits);
will it not work if the image is created in this way.
thanks for your help.
omar lodhi
|
|
|
|
|
If you just need to load and draw a bitmap from a file, use LoadImage[^] to load the bitmap, and then normal drawing techniques.
Software Zen: delete this;
|
|
|
|
|
Can you use of CImage class?
|
|
|
|
|
Hi,
actually i can not use any built in image loading method because the image file that i have to read contains lot of images so i will read one image at a time from that file using some standard file functions and then will try to draw them. i know using built in image loading methods are very easy.
So please tell me how can i create image from the raw data.
omar lodhi
|
|
|
|
|
Is this line succeeding?
m_bmpBackImage.SetBitmapBits(bmih.biWidth*bmih.biHeight, byBmp + bmfh.bfOffBits);
bmih.biWidth*bmih.biHeight will only work for 8-bit bitmaps that have a width aligned to a
multiple of 4 bytes.
Here's a generic method of calculating bitmap image size that will work for all bit depths.
LONG BytesPerLine = (((bmih.biWidth * (long)bmih.biBitCount + 31L) & (~31L)) / 8L);
m_bmpBackImage.SetBitmapBits(BytesPerLine * (bmih.biHeight > 0 ? bmih.biHeight : -bmih.biHeight),
byBmp + bmfh.bfOffBits);
You could also use bmih.biSizeImage if it's not 0.
|
|
|
|
|
Another item....you should use SetDIBits() instead of SetBitmapBits()
|
|
|
|
|
Hi,
Here is code that i use to create image.
file = fopen(m_csBkImagePath, "rb");
fseek(file, SEEK_END, SEEK_END);
nSize = ftell(file);
byBmp = new BYTE[nSize];
fseek(file, SEEK_SET, SEEK_SET);
memset(byBmp, 0, nSize);
fread(byBmp,nSize, 1, file);
BITMAPFILEHEADER bmfh;
memcpy(&bmfh, byBmp, sizeof(bmfh));
BITMAPINFOHEADER bmih;
memcpy(&bmih, byBmp + sizeof(bmfh), sizeof(bmih));
int nRet = m_bmpBackImage.CreateBitmap(bmih.biWidth, bmih.biHeight, bmih.biPlanes, bmih.biBitCount, NULL);
nRet = m_bmpBackImage.SetBitmapBits(bmih.biSizeImage, byBmp + bmfh.bfOffBits);
delete [] byBmp;
here is the drawing code that i use to draw the image.
dcMemBkImage.CreateCompatibleDC(pDC);
dcMemBkImage.SelectObject(&m_bmpBackImage);
GetObject(m_bmpBackImage,sizeof(bitmap),&bitmap);
pDC->BitBlt(m_nLeft, m_nTop, bitmap.bmWidth, bitmap.bmHeight, &dcMemBkImage, 0, 0, SRCCOPY);
dcMemBkImage.DeleteDC();
but nothing is displayed only white image.
is there any reference code i can see. no one has faced this type of problem before?
thanks for all people responses.
Omar Lodhi
|
|
|
|
|
I changed the code a bit so I could test it, but here's a couple examples that hopefully you can
extract some useful parts from (note that I assumed drawing from a window class so I used a
CClientDC).
To convert the DIB to a DDB and draw the DDB:
FILE *file = fopen("C:\\test.bmp", "rb");
fseek(file, SEEK_END, SEEK_END);
long nSize = ftell(file);
BYTE *byBmp = new BYTE[nSize];
fseek(file, SEEK_SET, SEEK_SET);
fread(byBmp,nSize, 1, file);
fclose( file );
BITMAPFILEHEADER *bmfh = (BITMAPFILEHEADER *)byBmp;
BITMAPINFO *bmi = (BITMAPINFO *)(byBmp + sizeof(BITMAPFILEHEADER));
BITMAPINFOHEADER *bmih = (BITMAPINFOHEADER *)bmi;
CClientDC dc(this);
CDC dcMemBkImage;
dcMemBkImage.CreateCompatibleDC(0);
CBitmap m_bmpBackImage;
LONG lScanLines = bmih->biHeight > 0 ? bmih->biHeight : -bmih->biHeight;
int nRet = m_bmpBackImage.CreateCompatibleBitmap(&dc, bmih->biWidth, lScanLines);
::SetDIBits(dcMemBkImage, m_bmpBackImage, 0, lScanLines, byBmp + bmfh->bfOffBits, bmi, DIB_RGB_COLORS);
delete [] byBmp;
...
CClientDC dc(this);
CBitmap *pOldBitmap = dcMemBkImage.SelectObject(&m_bmpBackImage);
BITMAP bitmap;
::GetObject(m_bmpBackImage,sizeof(bitmap),&bitmap);
dc.BitBlt(50, 50, bitmap.bmWidth, bitmap.bmHeight, &dcMemBkImage, 0, 0, SRCCOPY);
dcMemBkImage.SelectObject(pOldBitmap);
dcMemBkImage.DeleteDC();
An alternative is to draw the DIB bits without converting to a DDB:
FILE *file = fopen("C:\\test.bmp", "rb");
fseek(file, SEEK_END, SEEK_END);
long nSize = ftell(file);
BYTE *byBmp = new BYTE[nSize];
fseek(file, SEEK_SET, SEEK_SET);
fread(byBmp,nSize, 1, file);
fclose( file );
BITMAPFILEHEADER *bmfh = (BITMAPFILEHEADER *)byBmp;
BITMAPINFO *bmi = (BITMAPINFO *)(byBmp + sizeof(BITMAPFILEHEADER));
BITMAPINFOHEADER *bmih = (BITMAPINFOHEADER *)bmi;
LONG lScanLines = bmih->biHeight > 0 ? bmih->biHeight : -bmih->biHeight;
CClientDC dc(this);
::SetDIBitsToDevice(dc, 50, 50, bmih->biWidth, lScanLines, 0, 0, 0, lScanLines, byBmp + bmfh->bfOffBits, bmi, DIB_RGB_COLORS);
delete [] byBmp;
-- modified at 22:07 Monday 1st January, 2007
*EDIT* Fixed code in first example
-- modified at 22:15 Monday 1st January, 2007
|
|
|
|
|
Thanks a lot ,
you have solved my problem.
thanks again.
omar lodhi
|
|
|
|
|
Hi all,
HiEdit V1.0.1.4 has been released. HiEdit is a multi-tabbed, high speed, large file edit control. It uses no more than ~140K of memory due to its sophisticated memory management. It supports most standard edit/richedit control messages and many custom ones. You can use it with any programming language since it is packaged as a standard dll and a static library. A full source demo application (written in Assembly) is inluded. You can get it here[^].
In addition, you can get HiEditor V1.0.1.5 (a full blown application that uses HiEdit)
Any feedback/suggestions is highly appreciated
Regards,
Antonis Kyprianou
-- modified at 3:53 Friday 29th December, 2006
http://www.winasm.net
|
|
|
|
|
|
Thanks for your reply. There is no question. HiEdit is a custom control that can be used in your applications and I wanted to let you know, in case you are interested.
Regards,
Antonis
http://www.winasm.net
|
|
|
|
|
Haven't read point no. 10 in Chris's sticky post at the top ?
"No advertising or soliciting."
|
|
|
|
|
akyprian wrote: In addition, you can get HiEditor V1.0.1.5 (a full blown application that uses HiEdit)
Any feedback/suggestions is highly appreciated
ads are not allowed here, as per forum guidelines, you better post article here, expect the any feed back there
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
Excuse my ignorance, but is the post about a free custom control considered as an ad? If so, please delete my post. Only questions are allowed?
http://www.winasm.net
|
|
|
|
|
akyprian wrote: Excuse my ignorance, but is the post about a free custom control considered as an ad? If so, please delete my post. Only questions are allowed?
i am not Admin here, i just showing you way to get good feedback
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|