|
|
Could you please tell me how to save to disk a bitmap stored in a HBITMAP structure? thanks in advance.
|
|
|
|
|
check out these structures
BITMAPINFO
DIBSECTION
BITMAPFILEHEADER
ofstream
post when need more clues
Kuphryn
|
|
|
|
|
use GetDIBits to create a DIB from the HBITMAP
then, fill out and write a BITMAPFILEHEADER
then write the DIB
that's it
Why donchoo take a peekchur mayn?
OK, cleeeeek
|
|
|
|
|
You can use fron CImage and attach this handle to it and use from save in this class
|
|
|
|
|
I searched for a solution but I couldn't find one. Probably what I'm looking for is somewhere out there but I can't find it. I don't like that I have to post a question here or anywhere and bother you with my problems but I'm sick of nasty bugs (very nasty). So here's the problem:
I create a directory with CreateDirectory(path,NULL) ,then I make a few folders in that directory and after that I try to delete that first directory.
And what happens - an error window pops up and says it cannot delete the folder because it is used by another program or person (mine ofcourse). I think this is caused by some unclosed handles maybe. I don't know. Damn nothing works when I want it to work. I'll be very greatfull if someone helps me. And this problem occurs only when I make new folders in that one folder. If it's empty
it's no problem to delete it. Unfortunately I'm not a programmer (yet) and I can't fix all the bugs.
...
After a few hours:
I fixed the bug. And I'm very sorry that I had to post a question that I could answer my self, but at the when I posted it I didn't knew the answer ofcourse. I'm sorry again for the disk space my question takes. It was a pretty simple mistake, but nasty. When I was checking do folders with the default folder name "New Folder" exist, I had to open a handle to the folder
to check if it existed. And I didn't close that handle. That was my mistake. Silly me. And here is the code that finds a name (that it's not already in use by another folder) for the new folder:
do{
CString num;
num.Format("%d",count);
newDirName=path;
if(newDirName.GetAt(newDirName.GetLength()-1)!='\\'){newDirName+='\\';}
newDirName+="New Folder ("+num+")";
ftest.HCloseHandle(); //Note: This is line I was missing before.
ftest.HSetFileName(newDirName);
count++;
}while(!ftest.HGetFileHandle());
I again apologize for posting this question. I hope no one's angry at me.
After a day(approximately):
I liked Gary R. Wheeler's reply. Thank you for your words man.
When I wrote the above stuff it was 2 or 3 am and I was tired, nervous and sleepy. I was amazed when I saw how many syntax errors I have made.
0000000001001011 0000000001000101 0000000001000001
-- modified at 13:36 Saturday 29th July, 2006
|
|
|
|
|
100110001001011010000 wrote: I again apologize for posting this question.
There's no need to apologize. You asked a reasonable question in a polite fashion. When you found the answer yourself, you updated your post so that people would know it. If you feel it was a 'silly mistake', that's OK; you'll remember better next time.
The questions that piss people off are the ones that ask for homework to be done, 'demand' a response, or insult a responder. We're not here to do your homework for you. Telling me to 'give you the source code by 3:00' (note no mention of the word 'please') doesn't instill in me a priority to answer the question for you. I've had posters tell me I was an idiot when I told them what they were trying to do was the wrong approach, and they needed to switch to another method. You can imagine how motivated I was to continue helping them .
The other class of annoying questions are those that could be solved by a simple search through the MSDN[^] or even Google[^]. Those of us who like to answer questions on the CP forums expect you to have at least tried to answer the question yourself. You did that, in fine fashion.
Software Zen: delete this;
|
|
|
|
|
Im in any of the functions in the Doc.cpp file.
I can use this code:
<br />
CFrameWnd *pWndMain = (CFrameWnd *)AfxGetMainWnd();<br />
ASSERT(pWndMain != NULL);<br />
<br />
CDocument *pDoc = pWndMain->GetActiveDocument();<br />
ASSERT(pDoc);<br />
<br />
POSITION pos = pDoc->GetFirstViewPosition();<br />
CView *pView = NULL;<br />
<br />
while (pView = pDoc->GetNextView(pos))<br />
{<br />
to get a pointer to a CFormView or CDialog that I might have. The
CView *pView pointer lets me access individual items in that CFormView.
If my CFormView has a property sheet with a few property pages, how can
I get a pointer to these property sheets from CDoc? I have:
CView1PropertySheet* m_pView1PropertySheet;
under my CFormView, but I cant see it and cant access it using the
pView pointer that I created this way.
Im stumped.
Please, any response any one can give me will be greatly appreciated.
Sincerely,
Danielle Brina
|
|
|
|
|
You will need to add an accessor method to your view class to return the pointer to your sheet:
CPropertySheet* CMyView::GetPropertySheet()
{
return m_pView1PropertySheet;
}
To get access to the pages, you can use CPropertySheet::GetActivePage or CPropertySheet::GetPage (see MSDN).
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
|
|
|
|
|
Hello , can anybody help me.. i want to Extract a Single Frame from a CImageList and want to show the Extracted Image to a CStatic Control. im using this method to Load and show the Bitmap to CStatic Control : --->
//////////////////////////////////////////////////////
//////////////////////////////////////////////
/////////////////////////////////////////
BOOL CXXXDlg::OnInitDialog()
{
..................
..........
// CImageList to load bitmap from Outside
CImageList m_imgList;
HIMAGELIST hImageList = ::ImageList_LoadImage(
AfxGetInstanceHandle (),
_T("C:\\xxxx.bmp"),
64, 32,
RGB(255,0,255),
IMAGE_BITMAP, LR_LOADFROMFILE);
/*Copies the Single (Image)Frame from the Image List to CBitmap */
CBitmap *hBmp = new CBitmap;
and
CBitmap hBmp;
if(NULL != hImageList)
{
BOOL bRet = m_imgList.Attach(hImageList);
GetImageFromList(&m_imgList , 0 , &hBmp );
and
GetImageFromList(&m_imgList , 0 , hBmp );
//////////////////////////////////////////////
// This is the CStatic Control on the Dialog //
m_bBit.SetBitmap((HBITMAP)&hBmp);
and
m_bBit.SetBitmap((HBITMAP)hBmp);
/////////////////////////////////////////
...........
.................
}
void CXXXDlg::GetImageFromList(CImageList *lstImages, int nImage,
CBitmap *destBitmap)
{
//First we want to create a temporary image list we can manipulate
CImageList tmpList;
tmpList.Create(lstImages);
//Then swap the requested image to the first spot in the list
tmpList.Copy( 0, nImage, ILCF_SWAP );
//Now we need to get som information about the image
IMAGEINFO lastImage;
tmpList.GetImageInfo(0,&lastImage);
//Heres where it gets fun
//Create a Compatible Device Context using
//the valid DC of your calling window
CDC dcMem; dcMem.CreateCompatibleDC (GetWindowDC());
//This rect simply stored the size of the image we need
CRect rect (lastImage.rcImage);
//Using the bitmap passed in, Create a bitmap
//compatible with the window DC
//We also know that the bitmap needs to be a certain size.
destBitmap->CreateCompatibleBitmap (this->GetWindowDC(),
rect.Width (), rect.Height ());
//Select the new destination bitmap into the DC we created above
CBitmap* pBmpOld = dcMem.SelectObject (destBitmap);
//This call apparently "draws" the bitmap from the list,
//onto the new destination bitmap
tmpList.DrawIndirect (&dcMem, 0, CPoint (0, 0),
CSize (rect.Width (), rect.Height ()), CPoint (0, 0));
//cleanup by reselecting the old bitmap object into the DC
dcMem.SelectObject (pBmpOld);
}
//////////////////////////////////////////////////////
///////////////////////////////////////////////
//////////////////////////////////////////
The Application Compiled n Build n Runs Succesfully ! , but it does not shows the Extracted Bitmap Frame
can anyone please tell me how to do tht... ???? pleasee
|
|
|
|
|
I think you dont have a valid hbitmap in your code
|
|
|
|
|
First, excuse me for posting in this news group, but there did not seem to be one that was appropriate.
I thought I would try a simple setup project using the Setup Project template, but when I tried to build it, it could not find the MsiLoader.Bin file at the location below:
Could not find file 'C:\Program Files\Microsoft Visual Studio .NET\Common7\Tools\Deployment\.\MsiRedist\1033\MsiLoadr.Bin' 'No such interface supported'
The file is there though, but not at that path. It is in the location:
C:\Program Files\Microsoft Visual Studio .NET\Common7\Tools\Deployment\MsiRedist\1033
Why does it look in the wrong place and how do I tell the compiler to look in the correct directory? I looked for a place to set the directory, but I could not find it.
Roj
|
|
|
|
|
The two paths are equivalent. The "\.\" intermediate path is equivalent to a single "\". The problem therefore is not one of finding the file, but something contained in the file.
Look at the error message: No such interface supported. You are making some kind of reference to an 'interface' supplied by the indicated file.
Software Zen: delete this;
|
|
|
|
|
hi all,
I want to develop a plugin for pocket windows media player, prefarably in c++, and I do not know where to start... can you plz provide any useful information or links???
What do I need?? Where to start??
Thanx alot
And ever has it been that love knows not its own depth until the hour of separation
|
|
|
|
|
Hi,
I'm having a general C program where I allocate two variables with predefined amount of memory depending upon the # of seconds user enters (this is a data acquisition program). It looks as follows where sizeof(float64) = 8 bytes-
float64 *dataAI;
dataAI = malloc(acq_time*sizeof(float64)*10000000);
using above I can allocate upto 14sec (acq_time = 14) without any problem, but whenever I try to allocate more than that, it simply does nothing (it allocates nothing) and goes to next statement.
Is there any memory allocation limitation in C??
I tried allocating same amount of memory using two variables rather than one, but even then it allocates only to one variable and does nothing for the second one. As follows (where acq_time = 16 or 18)-
float64 *dataAI1, *dataAI2;
dataAI1 = malloc((acq_time/2)*sizeof(float64)*10000000); //allocates for this
dataAI2 = malloc((acq_time/2)*sizeof(float64)*10000000); // does nothing for this
How can I get around this problem . Any suggestions??
thanks,
-Pavan
|
|
|
|
|
pavanbabut wrote: dataAI = malloc(acq_time*sizeof(float64)*10000000);
That basically equates (roughly) to allocating 80 MB * some value of time (so for 14, it is 1.1 GB of data). It is VERY bad to try and allocate that much space. Generally, the heap won't let you allocate more than 1 GB. If you are allocating chucks close to 100 MB at a time, you really should start thinking of another way to solve your problem since you are putting way too much into memory at one time.
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
|
|
|
|
|
The porblem is, I acquire data continuously at 10MSamples/sec (where each sample is of 8bytes) per channels with 3 channels at a time. Where one channel is of type float64 and another two are of type uint8 (1byte). So, when I start the NI board to acquire data, it continuously records data for the specified time and stores the data (onto ram, at present) simultaneously. Coming to my hard disk, its speed is around 13MB/s (write speed) even though its a SCSI drive and so, I can not write data onto hard disk at the same speed or atleast near to that speed. It would really appreciate if you have any other idea on implementing this, with out getting any errors.
thanks,
-Pavan
|
|
|
|
|
I don't know what your requirements for the project are, but here are some suggestions:
1) If you can, try to take a sampling of the data. Instead of pulling in all of it, pull in 3 or 4 sets per second.
2) Buffer the data into a smaller section. Pull in some small set of data (say 13 MB) and write it to a file when it is full. During the write process, block all incoming data until you are done
3) Similar to #2, if you can spawn multiple threads, create a buffer, fill it up, and then pass it to a thread to write it out to a file. While it is writing, you create a new buffer (or keep a pool of buffers around for this -- which would be more efficient) to write to.
4) If none of those will do, and you absolutely must allocate all the necessary memory up front (which, I would question those requirements if that is the case), you will need to create your own heap management (meaning, you will need to override the new and delete operators to suit your needs). This is NOT recommended and again, if you really think this is what you need, then I would question your requirements.
Where are you receiving these samples from? That is, are they coming over a serial port? ethernet port? USB/firewire? hard drive?
Keep in mind that when you declare large blocks of memory (such as 1.1 GB), you will be leaving RAM and using virtual memory (meaning that you will be reading/writing to the hard drive continuously for this). From your description of the problem, you will not be able to make use of that since the hard drive write speed can't keep up with your sampling rate.
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
|
|
|
|
|
From a long time I am thinking on the same lines as your 3rd suggestion. But, I doubt that at somepoint the buffer will over run or we may skip data (as the HDD speeds are very very low compared to acquiring speeds). Actually the data of the 3 channels comes from a National Instruments Data Acquisition PCI board, the 3 channels (VIdeo signal, Hsync and Vsync)are connected to the board. I have seen that SCSI drives can write at around 150MB/s speeds. If I can get my SCSI drive to drive at that speeds, I think my problem will be solved for the most part. Maybe now I am thinking more onto hardware side, do you think I can improve my drive speeds. I dont understand why it has such slow speeds while it is an U320 SCSI interface (ofcourse its not in any RAID array configuration, its the only drive the system is having) and being a workstation system (dell PWS 650).
wil keep trying your other suggestions too.
thanks,
-Pavan
|
|
|
|
|
So this information is coming from an PCI board? I'm surprised you get that high of a data rate using PCI ... but anyway. Try this:
1) Create a pool of 10-20 byte buffers to recieve your data.
2) Pull data from your device and load it into the first buffer.
3) When the buffer is full, pass it off to a thread to write out the data
4.1) Your main thread will select the next available buffer and continue to place the received data in it.
4.2) Your write theads will write the data to a file (presumably locking the file so you don't get sync errors) and then release the buffer back to the available pool.
5) Repeate 2-4 until complete.
Your buffers will need to be small enough that you can easily allocate the memory for them, but large enough so that your write operations will be optimal (that is, if your drives write at 13 MB/sec, 13 MB might be a good size for you). If you want to get really daring, you might try to create a set of thread pools as well (just to gain some efficiency by not creating and closing threads constantly).
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 tried both ways, but still either I am not able to keep up with the read speed or the porgram hangs by taking up 100% of processor. Here are the 2 ways I tried for-
Method1-
1) Created 5 different same size buffers for each of the 3 channels (so 3x5 = 15 different buffers) where the buffers for channel one are of size 100000*6bytes each and that of channels 2&3 are of 100000*1byte each.
2) Created 15 threads to process each of those 15 buffers whenever they are ready (initiated by the main acquisition thread as soon as a buffer becomes ready).
3) Created different binary files to write the corresponding buffer data (to overcome the file access issue).
-In this case the program hangs as soon as I run it and locks the processor at 100% (I think its due to the pool of threads ruuning at the same time).
Method2-
1) Created only 3 threads (for each channel data) to write any of the 5 buffers (allocated in the same fashion as before) depending upon their corresponding buffer flags (again initiated by the main acquisition thread, same as before).
2) Created only 3 files to write the data into (since at any given point of time, only 1 buffer is being accessed by the corresponding threads).
-In this case too, my porcessor is being locked up for a while and at some point the data acquisition board gives out buffer overrun error.
Here is a sample of how I am writing my thread-
DWORD WINAPI StartAThread0(LPVOID param)
{
wwrite_ASignal0(); //for buffer[0] of channel1
return 0;
}
void write_ASignal0()
{
int i, dataA, dataA1 = -8191;
do
{
if (m_bUpdateA[0])
{
for (i=0; i<100000; i++)
{
if (dataAI[0][i] < 0)
fwrite(&dataA1, sizeof(int), 1, streamA[0] ;
else
{
dataA = (int)((dataAI[i][0]-1.25)*6552.8);
fwrite(&dataA, sizeof(int), 1, streamA[0] ); }
}
m_bUpdateA[0] = false;
}
}while(m_bInitialize);
}
Where m_bInitialize keeps the thread running waiting for m_bUpdate[0] to activate. As soon as it does it writes the buffer to the corresponding file and deactivates the flag. In the sam fashion I am having for all the other 14 threads.
Here is my application to be exact-
The board is a Nation Instruments Data Acquisition board which can acquire data at a max of 10MHz. The data is acquired using their own native commands in C. The minimum buffer size I can use to acquire data is 10000 and then 100000. Any number other than these will give out buffer overrun error. So if I use 100000 samples, it means that the board acquires data at 10000000 samples per sec in small chucnks of 100000samples/channel, while syncronizing b/n the board memory and the memory allocated by us. At last the baord acquires 100 chucnks of these data packets to finish off 10MSamples/channel. So, in 1000msec it is acquiring 100 sets of 100000data samples/channel = 10msec/set/channel. When I test my present program for the time it takes to write 100000samples of data on to HDD it shows 14-16msec (so I am having a lag of atleast 4msec, which does have a large effect I think).
This is my observation till now. Plz. do lemme know if you come up with a different idea for implementing this thing.
thanks,
-Pavan
|
|
|
|
|
Well, here's your problem:
fwrite(&dataA, sizeof(int), 1, streamA[0] );
You need to reorganize this into a single write - have your buffers as a coninuous block of bytes and do the single operation in a single WriteFile call.
Also, try using CreateFile, Readfile, and WriteFile and avoid the 'C' functions, which have to get decoded into one of the other three calls anyways.
I usually have two layers in a case like this:
Aquisition -> Buffer Writes
Buffer Read -> Disk Writes
You just need to synchronize the access t your 'buffer pointers' between the threads.
Only two threads required, one doing IO and one doing disk writes.
Also, defragment hte hard drive frequently and defragment the paging file.
Turn off the Virus Scnaner if possible, at least on the folder doing the disk IO.
Any sufficiently gross incompetence is nearly indistinguishable from malice.
|
|
|
|
|
Hi,
thanks for your reply. I tried to use WriteFile, but how can I write non-text data using this command. It writes text data fine, but not any other datatypes. Also where can I set the mode to binary while creating the file using CreateFile (I have seen lot of flags, but none relating to binary mode).
One more thing I would like to point out is, my porgram does I/O operations in a single function (it acquires the 2 digital channels data at the same time it acquires analog channel data). So I need to do the disk write operations for the 3 channels data at the same time within the time delay of next I/O or atleast within a span of 5 buffers. So, atlast my read-in rate is (100000x6bytes + 2x100000x1byte) data every 10msec. So I need to write that much data to 3 different files at the same time.
I am using fwrite(&dataA, sizeof(int), 1, streamA[0] );, instead of writing the buffer in a single function, as I need to convert the datatype from 6bytes to 2bytes (using some scaling function) and from 1byte to 2bytes data. But I can do that even after I do the acquisition, if it can resolve my problem.
thanks,
-Pavan.
|
|
|
|
|
The low level File IO does not 'care' about text versus binary. Createfile always makes a binary data file. You only make it a 'text' file by choosing to add CRLF or LF or LFCR or whatever to the 'end' of a line.
Youc an write out an entire block of memory with a single functionc all to Writefile. You are killing your performance with the thousands of individual fwrite calls.
Any sufficiently gross incompetence is nearly indistinguishable from malice.
|
|
|
|
|
I did time comparison between the two functions fwrite and writefile for writing 800000 bytes of data and they both take same amount of time (among 20 trails).
I tried using 1 thread for writing all the 3 channels data using 10 buffers for each channel (once the IO records data into 1 buffer, it updates the corresponding buffer flag and as soon as it updates the write thread writes the corresponding 3 channels buffers to file and updates the correspoding flags to false. I tried this for 10 times for acquiring data about 5sec, in those 3 times it gave out files of same size and 3 times it gave out different size files (so I think it is missing some data in between while writing). Will check and try different methods of implementation and see if I can acheive it.
thanks,
-Pavan
|
|
|
|
|