|
Hi,
//Formatting of the code supplied
I am writing an application which supports loading, processing, and displaying of various image file formats.
I have a class, CDib, derived from CBitmap that displays the bitmap data on the device context supplied using BitBlt(...). I think this is a fairly general way dc voodoo.
//!Code Snippet (1)
//!CDib is derived from CBitmap
//!@param dc: reference to CDC where the image is to be drawn
//!@param pbm: CBitmap pointer that contains the image data, in most cases a pointer to itself
<code>
BOOL CDib::Draw(CDC& dc, CBitmap* pbm, const CRect* rcDst, const CRect* rcSrc)
{
CRect rc;
if (!rcSrc) {
// if no source rect, use whole bitmap
rc = CRect(CPoint(0,0), GetBitmapSize(pbm));
rcSrc=&rc;
}
if (!rcDst)
// if no destination rect, use source
rcDst=rcSrc;
bool bRet;
//Create a memory DC and load the bitmap onto it
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap* pOld = (CBitmap*)(memDC.SelectObject(pbm));
if(rcSrc->Size() == rcDst->Size()){
bRet = dc.BitBlt(rcDst->left, rcDst->top,
rcDst->Width(), rcDst->Height(),
&memDC, rcSrc->left, rcSrc->top, SRCCOPY);
} else{
dc.SetStretchBltMode(COLORONCOLOR);
bRet = dc.StretchBlt(rcDst->left, rcDst->top,
rcDst->Width(), rcDst->Height(),
&memDC, rcSrc->left, rcSrc->top, rcSrc->Width(), rcSrc->Height(),
SRCCOPY);
}
//!Delete the memory DC
memDC.DeleteDC();
return bRet;
}</code>
This function works fine if I load a BMP file using CBitmap::LoadImage(...).
Now,since the program can load other image file formats, I tried using CBitmap::CreateBitmap(...) but that didn't work. So, what I have done now is to use CreateCompatibleBitmap(...) and CreateCompatibleDC(...) to create a CDC and CBitmap object, and then linked them together using SelectObject(..), and then use SetPixel(...), now the problem is that SetPixel(...) is very very slow. I want to ask the readers if there is an alternate way to SetPixel where I can load a chunk of image data to the CBitmap object, and then pass it to CDib::Draw(..) function.
<code>//!Code snippet 2
//!@param pData: image data that needs to be displayed
void CImageDraw::CreateBitmap(BYTE* pData)
{
//!Create a DC
CDC dc;
dc.CreateCompatibleDC(NULL);
//!If m_dib exists delete it
if((HBITMAP)m_dib)
m_dib.DeleteObject();
m_dib.CreateCompatibleBitmap(AfxGetMainWnd()->GetDC(), m_nImgWidth, m_nImgHeight);
CBitmap *pOldBitmap = (CBitmap *)dc.SelectObject(&m_dib);
for(int y = 0; y < m_nImgHeight; y++){
for(int x = 0; x < m_nImgWidth; x++){
//!This is very very slow.....I need an alternative
dc.SetPixel(x,m_nImgHeight-1-y, RGB(pData[3*x+2+y*m_nImgWidth*3], pData[3*x+1+y*m_nImgWidth*3], pData[3*x+y*m_nImgWidth*3]));
}
}
dc.SelectObject(pOldBitmap);
dc.DeleteDC();
}
</code>
Thanking in anticipation
Swati<code></code>
|
|
|
|
|
The reason I use such ugly code, is because that's the only code I know. I am a begginer in programming. At the moment I am reading some materials on STL and MFC, but find it quite difficult to understand, as I have a lot of gaps in my programming knowledge. To that I have no one to ask for help apart from the forum. So THANK YOU all for helping me out!
Maybe you could help me out with this error I get:
cannot convert parameter 1 from 'unsigned short' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast.
The solutions you helped me out with, was not exaclty what I was looking for. Basicaly pszData is only 1 character at a time. So I want to store that 1 character in an array, then add the next character that comes from pszData and add it to the array. When I have 10 characters, That's when I want to display on screen. pszData recieves a character at different times, could be a split second or a whole day.
Thanks in Advance!
void CChildView::SortData(LPCTSTR pszData)<br />
{<br />
TCHAR buffer[10];<br />
<br />
????? I have no idea what to put here ???? <br />
Can anyone please help me.<br />
<br />
buffer[10] = _T('\0');
DisplayData(buffer);<br />
There is no fixed set of rules according to which clear, understandable, and provable programs can be
constructed. There are guidelines, of course, and good ones at that; but the individual programmer's style
(or lack of it), his clarity of thought (or lack of it), his creativity (or lack of it), will all contribute
significantly to the outcome.
-- Peter J. Denning
|
|
|
|
|
hello there,
First of all, don^t forget that the first position in an array is position 0. so if you have an array of 10 elements the tenth element is at array[9]!
In the code you posted you should make your buffer an array of 11 if you want to do:
TCHAR buffer[11],<br />
...<br />
buffer[10] = _T('\0');<br />
Then to copy the first 10 chars of the pszData string you could use:
_tcsncpy( buffer, pszData,10); <br />
Hope this gets you along...
<edit>
Sorry I did not read your post completely correct at first
From what I understand this function will be called multiple times an after the tenth time you want to display the 10 chars passed. you could do like this:
void Childview::SortData(LPCTSTR pszData)<br />
{<br />
static int nPass=0;<br />
static LPTSTR buffer[11];<br />
buffer[nPass++] = pszData[0];<br />
if( nPass == 10 )<br />
{<br />
buffer[10] = NULL;<br />
DisplayData(buffer);<br />
nPass = 0;<br />
}<br />
<br />
}
Allthough I think it would be better if you just passed a single TCHAR as parameter and not the string, but that is up to you....
<\EDIT>
Davy
|
|
|
|
|
Thanks, I will try it... the reason I want to store it in an array, is because I want to sort out the data, There is actualy 80characters that I need to store in the array, and only send to the display about 10.
The program recievs data from a COM port(rs-232), I got the program from this website, and just want to modify it. I write simple code, as it's what I am familuar with.
Thanks!
are you australian?
|
|
|
|
|
tomek18 wrote:
are you australian?
Nope. I`m no bloke from down-under.
100% European. Born and raised in tiny Belgium, and about 5years ago moved to and still living in sunny Greece
Greetings,
Davy
|
|
|
|
|
GDavy wrote:
Born and raised in tiny Belgium
Cooool, a compatriot .
|
|
|
|
|
Potverdikke, It's great to see a Belgian!
|
|
|
|
|
Gotferdom yes
|
|
|
|
|
GDavy wrote:
buffer[nPass++] = pszData[0];
gives me error, I always get a simular error with other methods:
error C2440: '=' : cannot convert from 'const unsigned short' to 'unsigned short *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or funtion-style cast
GDavy wrote:
DisplayData(buffer);
error C2664 : 'DisplayData': cannon convert parameter 1 from 'unsigned short *[11]' to 'const unsigned short *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
What do you suggest I should try next?
|
|
|
|
|
I`m so sorry... I posted you a bug
Dont do LPTSTR buffer[11], but TCHAR buffer[11]
sorry
|
|
|
|
|
Thank's Dave! It works
Got another reoccuring problem you might help me with.
when I send a characters throught the com port, the other computer recieves them, and it is fine if each character is send no more then twice. But if it is so, then the 2nd computer recieves something like this, if 0 (zero) is send for example, it displays '00°0°0°0°0°0°0°0°0' it happened to me before, even so if I change the code to it's original form. To repair the program, I need to download the source code again, and re-complie.
What do you think the problem might be? Any suggestions?
Cheers.
btw. I am from downunder, and living in Germany.
|
|
|
|
|
Hi,
I am writing an application which supports loading, processing, and displaying of various image file formats.
I have a class, CDib, derived from CBitmap that displays the bitmap data on the device context supplied using BitBlt(...). I think this is a fairly general way dc voodoo.
//!Code Snippet (1)
//!CDib is derived from CBitmap
//!@param dc: reference to CDC where the image is to be drawn
//!@param pbm: CBitmap pointer that contains the image data, in most cases a pointer to itself
BOOL CDib::Draw(CDC& dc, CBitmap* pbm, const CRect* rcDst, const CRect* rcSrc)
{
CRect rc;
if (!rcSrc) {
// if no source rect, use whole bitmap
rc = CRect(CPoint(0,0), GetBitmapSize(pbm));
rcSrc=&rc;
}
if (!rcDst)
// if no destination rect, use source
rcDst=rcSrc;
bool bRet;
//Create a memory DC and load the bitmap onto it
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap* pOld = (CBitmap*)(memDC.SelectObject(pbm));
if(rcSrc->Size() == rcDst->Size()){
bRet = dc.BitBlt(rcDst->left, rcDst->top,
rcDst->Width(), rcDst->Height(),
&memDC, rcSrc->left, rcSrc->top, SRCCOPY);
} else{
dc.SetStretchBltMode(COLORONCOLOR);
bRet = dc.StretchBlt(rcDst->left, rcDst->top,
rcDst->Width(), rcDst->Height(),
&memDC, rcSrc->left, rcSrc->top, rcSrc->Width(), rcSrc->Height(),
SRCCOPY);
}
//!Delete the memory DC
memDC.DeleteDC();
return bRet;
}
This function works fine if I load a BMP file using CBitmap::LoadImage(...).
Now,since the program can load other image file formats, I tried using CBitmap::CreateBitmap(...) but that didn't work. So, what I have done now is to use CreateCompatibleBitmap(...) and CreateCompatibleDC(...) to create a CDC and CBitmap object, and then linked them together using SelectObject(..), and then use SetPixel(...), now the problem is that SetPixel(...) is very very slow. I want to ask the readers if there is an alternate way to SetPixel where I can load a chunk of image data to the CBitmap object, and then pass it to CDib::Draw(..) function.
//!Code snippet 2
//!@param pData: image data that needs to be displayed
void CImageDraw::CreateBitmap(BYTE* pData)
{
//!Create a DC
CDC dc;
dc.CreateCompatibleDC(NULL);
//!If m_dib exists delete it
if((HBITMAP)m_dib)
m_dib.DeleteObject();
m_dib.CreateCompatibleBitmap(AfxGetMainWnd()->GetDC(), m_nImgWidth, m_nImgHeight);
CBitmap *pOldBitmap = (CBitmap *)dc.SelectObject(&m_dib);
for(int y = 0; y < m_nImgHeight; y++){
for(int x = 0; x < m_nImgWidth; x++){
//!This is very very slow.....I need an alternative
dc.SetPixel(x,m_nImgHeight-1-y, RGB(pData[3*x+2+y*m_nImgWidth*3], pData[3*x+1+y*m_nImgWidth*3], pData[3*x+y*m_nImgWidth*3]));
}
}
dc.SelectObject(pOldBitmap);
dc.DeleteDC();
}
Thanking in anticipation
Swati
|
|
|
|
|
I have a data in the view, it is like column based.I would like to save that into .html format.I need the source for that.Plz.......
Ashok.R
|
|
|
|
|
I assume you have the data in your variables.
Open a file on the HDD with extension ".html";
CString str, strData;
str = "<html>[DATA]</html>";
now, you insert data into strData like this:
for (i = 0; i < items_to_be_inserted; i++
{
strData += your_values[i];
strData += "<br>";
}
str.Replace("[DATA]",strData);
Now write str down to the file.
You can do some formatting on your code, like put it in tables etc. For that, contact an HTML programmer.
this is this.
|
|
|
|
|
Hi all!
I have created a .resx file for Greek language using visual studio. That file supposed to be used by .NET projects that support this file. However afterwards they asked me to use the same file just as it is in C++ projects without .NET!
I found a C++ XML parser that works fine. The tags can be read with no problems, but when I have to read the string with the Greek characters I never get the desirable result. When i open the same file in notepad the Greek characters are printed fine. When i open it in WordPad i get the same result as i get in my console application. Does anyone have any idea why is that happening and how could i solve the problem?
|
|
|
|
|
before long, the program can run without error,but today it don't run.
m_pConnection.CreateInstance("ADODB.Connection") return 0, and there is the exception----First-chance exception in GIS.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
i write it in mfc.
how can figure it out ?
|
|
|
|
|
Is m_pConnection a pointer? Is it a valid object?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I have a source code written in borland c++.
How do I get it to run with visual c++
Thanks
Joe M
|
|
|
|
|
It depends of what you want to do... If these are simple classes that only use the standard C++ libraries, then you can just import them in your project.
|
|
|
|
|
when I run the code in visual c++, it's looking for
include file fstream.h.
How can I get that file/
Thanks
|
|
|
|
|
fstream.h is a header from the standard library...
is your program a console application, or windows ?
if it is a windowed apps, you'll have to learn from OWL to MFC or Win32...
one question, why do need to do such a thing ?
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hi all,
I am making a small tool, which scans a specific file on the whole hard drive. I am making this application via a small Dialog based application. My dialog window will have three buttons "Scan", "Exit" and "About". I have a doubt
1) When user clicks the "Scan" button, the "Exit" button should change to "Stop" so the user can click this "Stop" button to stop the scan, while my tool is scanning the hard drive. Basically this "Exit" should act like TOGGLE style.
How to do this ?
K.K.Senthil Velan
Information Assurance Engineer
|
|
|
|
|
Hello
You need to use threads to handle messages while your project scan hard disk
Iman Ghasrfakhri
|
|
|
|
|
Do it like this:
In header:
private:
BOOL m_bWorking;
public:
void DoScan();
static DWORD __stdcall ThreadScanner(LPVOID lpVoid);
-----
In OnInitDialog()...
m_bWorking = FALSE;
-----
In OnStartScan()...
DWORD id;
CreateThread(NULL,0,ThreadScanner,this,0,&id);
CButton* pButton = (CButton*)GetDlgItem(IDC_BTN_EXIT);//IDC_BTN_EXIT is the id for your Exit Button.
pButton->SetWindowText("Stop Scan");
m_bWorking = TRUE;
-----
DWORD __stdcall CScanDlg::ThreadScanner(LPVOID lpVoid)//where CScanDlg is you dialog class.
{
CScanDlg* pParent = (CScanDlg*)lpVoid;
pParent->DoScan();
return 0;
}
-----
In OnScan()...
while (m_bWorking)
{
Do the scanning here...
}
-----
in OnExit()...
if (m_bWorking == FALSE)
CDialog::OnCancel();
else
{
m_bWorking = FALSE;
CButton* pButton = (CButton*)GetDlgItem(IDC_BTN_EXIT);
pButton->SetWindowText("Exit");
}
Any problems understanding the code?
Please say if it does not work.
Happy Coding.
this is this.
|
|
|
|
|
khan++ wrote:
CreateThread(NULL,0,ThreadScanner,this,0,&id);
Since this is an MFC application, AfxBeginThread() must be used.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|