|
I am doing a project related to video/image processing in Win32 environment.
Now, I would do something like printing a bitmap file. The input parameter I get would be "standard bitmap format" data (ex: a buffer like BYTE*). So, how can I do with this buffer (ex: BYTE* ) and print the bitmap format to printer ?
Any response would be greatly appreciated !
|
|
|
|
|
A printer has a DC, you simply StretchBlt it from a DC containing your bitmap to the printer. You will *always* stretch it, because otherwise the image will be smaller than a postage stamp. Don't forget to set the COLORONCOLOR StretchBlt mode.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Christian, can you explain your answer a little bit more, cos I have had this problem on my app. I managed to fix it by stretchblt'ing it with an offset, however this only worked for my PC. I recently tested it on someone else's PC and it was like a postage stamp despite my offset. Again, ur input would be much appreciated,
Alan.
P.S. did u fix that problem you had with the min/max track size of the child window (where it wouldn`t resize below a 100?) cos I posted a reply, but I think u must've solved it by that time.
"When I left you I was but the learner, now I am the Master" - Darth Vader
|
|
|
|
|
You actually need to find out the size of the print DC for the specific printer you are working with. Also, some HP printers do not report this correctly if you're using DirectX, we spoke to HP about this and they said they know about the problem, but they will only fix it *in our app* ( they admit the problem is their drivers ) if we give them all our source code and a pile of money.
I do it like this:
CPrintDialog dlg(false);
dlg.GetDefaults();
HDC hdc = dlg.GetPrinterDC();
ASSERT(hdc);
CDC DC;
DC.Attach(hdc);
m_PrintAreaHorz = GetDeviceCaps(hdc, HORZRES);
m_PrintAreaVert = GetDeviceCaps(hdc, VERTRES);
DC.DeleteDC();
which gives me the width and height I need to stretch to in order to fill the page. This should work for any printer, that is, if you stretch to these co-ordinates ( you'll obviously not want to, for aspect ratio reasons as much as anything ), you will fill the printable area of the page on any size/DPI printer.
Chambers wrote:
P.S. did u fix that problem you had with the min/max track size of the child window (where it wouldn`t resize below a 100?) cos I posted a reply, but I think u must've solved it by that time.
No, I've left it for now. For some reasons the MinMax is right, but Windows is not letting me size down to a width of 50, it stops at 100. I think the problem is in our Python code, somewhere.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Thanks Christian, I`ve managed to get it going now, just hope it works on other PC's, wish me luck,
Many Thanks,
Alan.
"When I left you I was but the learner, now I am the Master" - Darth Vader
|
|
|
|
|
Good luck
Printing is a royal pain at times, but the way I showed you is the right way to get the dimensions for every page. I did three implimentations of printing in different apps before I felt I was doing it *well*. I'm not especially keen on how MFC puts it all together, either.
"Only a master of evil, Darth"Obi Wan Kenobi
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
CPrintDialog dlg(false);
dlg.GetDefaults();
HDC hdc = dlg.GetPrinterDC();
ASSERT(hdc);
CDC DC;
DC.Attach(hdc);
m_PrintAreaHorz = GetDeviceCaps(hdc, HORZRES);
m_PrintAreaVert = GetDeviceCaps(hdc, VERTRES);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
DC.DeleteDC();
Christian,
Thanks for your reply.
But I got another question as quoted as "^^^^^" above.
Does this print to the "original size" of this bitmap file ? (i.e, original width and height of this bitmap)
|
|
|
|
|
Well, it's given you the width and height of the print DC, it's got nothing to do with the bitmap. You'll need to know the physical size of the paper ( A3, A4, Legal) in order to turn that into something physical and then you need to use these values with respect to aspect ratio correction as well.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
And, another question...
If, what I get is just a buffer like RGB-24 data ? How to print it ?
Do I need to convert or save it as a standard BMP format ?
How to do that ? (i.e, save RGB-24 data to BMP format ?) What kind of header do I need to add ? Or how can I get the dimension (i.e, width and height) from this RGB-24 data ?
Any reply would be greatly appreciated..
|
|
|
|
|
You cna pass the buffer into a CBitmap constructor, although I'm not sure if a printer DC will print any bit depth DDB. I'd play it safe and create a DIBSection, then you can just memset the buffer into it.
If you call CreateDIBSection, you get a pointer to the data and you can copy your buffer into it.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
If I use StretchBlt, can I print "color" image ? (I mean, if my printer is color...)
Another API I found is: DrawDibDraw, can I also use this API to print "color" image ?
|
|
|
|
|
manio wrote:
f I use StretchBlt, can I print "color" image ? (I mean, if my printer is color...)
OF course, that is what COLORONCOLOR is for, to smooth the colours when stretching.
manio wrote:
Another API I found is: DrawDibDraw, can I also use this API to print "color" image ?
Must be - no point having a 2 color DIB. I believe this API is part of VFW, I know Chris' DIBSection wrapper uses it and I believe it does dithering. But I've never used it so I can't comment beyond that.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Christian,
One more question about StretchBlt..
suppose my bitmap data to be printed is in some buffer like this:
pCurrentImage, (i.e, as the following
class CRGBImage
{
public:
BYTE* data;
int m_nWidth; // in pixel
int m_nHeight;
};
Now I already get something like this: CRGBImage* pCurrentImage...
Then I want to print this image data, so I wrote the following codes.
CPrintDialog dlg( FALSE );
CDC dc;
dc.Attach( dlg.GetPrinterDC() );
//calculate printing area(width and height)
int pwidth = dc.GetDeviceCaps(HORZRES);//get width of printing area
int pheight = dc.GetDeviceCaps(VERTRES);//get height of printing area
Now, how can I copy my bitmap data to dc ?
And, for the following StretchBlt API:
BOOL CDC::StretchBlt( int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, DWORD dwRop );
(Take the width for example)
The above parameter nSrcWidth = pCurrentImage->m_nWidth, right ?
And, how about the nWidth ? How to calculate it if I want to print to the original dimension of my bitmap ?
How to calculate pSrcDC ? (Do I just use: dc.StretchBlt(...) as dc mentioned above ? Because there are 2 DCs, I got kind of confused !! )
And, when to put "COLORONCOLOR StretchBlt mode" as you mentioned last time ?
I know I probably asked too many questions. Your any reply would be greatly appreciated..
|
|
|
|
|
manio wrote:
Now, how can I copy my bitmap data to dc ?
Not AFAIK, in that the command that does this is StretchBlt. I would imagine writing an equally efficient streching routine that does COLORONCOLOR would be tedious, and kind of redundant when it's in front of you. Just create a DIBSection with the width and height, you have a DSC if you want, but if you don't specify PAL_COLORS the DC paramater can be NULL anyhow. Then bitblt your bits into it, and stretchblt to the screen. Yes, you need to make another copy to do that, but that's really the best way I can see.
manio wrote:
And, how about the nWidth ? How to calculate it if I want to print to the original dimension of my bitmap ?
Like I said before, your original bitmap has a dimension that relates to the resolution and size of your monitor - it's NOT a real number, it's a number of pixels. Or do you mean aspect ratio ? Use the ratio of bitmap width to height to calculate the size of the aspect you're not filling the page with. If that comes out too big for the page, use the other one.
For example, if my bitmap is 2 x 3 pixels and I am drawing with a width of 6, I get the height by going 6 * 3 /2 = 9.
manio wrote:
How to calculate pSrcDC ? (Do I just use: dc.StretchBlt(...) as dc mentioned above ? Because there are 2 DCs, I got kind of confused !! )
Once you've created the DIBSection you need to select the HBITMAP returned from CreateDIBSection into a DC. Create it like this:
CDC srcDC;
srcDC.CreateCompatibleDC(&dc);
Now the DC is compatible with the print DC. Select your image into it, and stretchblt. Don't forget to go dc.SetStretchBltMode(COLORONCOLOR);
manio wrote:
I know I probably asked too many questions. Your any reply would be greatly appreciated..
Printing is a pain, printing graphics doubly so. I hope this helped.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
in the View.h file there is a method,
public:
CXXXDoc* GetDocument();
but there is no CXXXDoc related information declared before we use it,
and sometimes if i add some members to the CXXXView.h, I should Add the
declaration
class CXXXDoc;
before i can sucessfuly compile it.
why?
thanks
|
|
|
|
|
That's called forward declaring. You're telling the compiler that CXXXDoc is a class. Since you're not actually referencing the class in the .h file, that's all the compiler needs to know at this point (It's a pointer to a class).
If you had a function which accessed the class such as:
CXXXView::dosomething(){GetDocument->DoSometing();};
Then you would need to include the header.
--
Where are we going? And why am I in this handbasket?
|
|
|
|
|
Hi!
I need some help with one of my programs. It won't start unless Visual C++ is installed on the computer. If Visual C++ isn't installed then nothing happens when I try to start the program. Does anybody know what might cause this? I've used the dependency checker in Visual C++ to see if there are any DLLs missing but the program doesn't find anything wrong...
|
|
|
|
|
Which version of the VC++ are you using (standard, professional)?
Are you using some ActiveX controls in your applications?
What type of application it is, MFC, ATL etc?
Please try to use the Dependency Walker (or Depends) utility to find out which components your application depends on.
Best regards,
Paul.
Paul Selormey, Bsc (Elect Eng), MSc (Mobile Communication) is currently Windows open source developer in Japan, and open for programming contract anywhere!
|
|
|
|
|
Hello C++_Beginner,
1. It sounds like the reason for the failure to launch is due to one or more DLLs missing.
There is a very good tool at the SysInternals web site called "FileMon". The following is the link to it :
http://www.sysinternals.com/ntw2k/source/filemon.shtml
This program is available in Win9x, WinNT, Win2K and XP versions. It basically monitors all file activities including file openning and closing.
If there are any missing files (including DLLs) while your app is launching, this program will report it.
2. The other possible reason for failure is missing registry entries. Another tool at SysInternals called "RegMon" which monitors registry activities.
The following is the web address :
http://www.sysinternals.com/ntw2k/source/regmon.shtml
This may help you to identify missing registry entries that are required by the system to identify further DLLs (e.g. COM servers).
Try out these two utilities and I'm very sure they will be of great help to you.
Best of luck.
Regards,
Bio.
|
|
|
|
|
Did you compile in Release mode? if not, your program is linked against debug libraries, and will never work without VC.
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Why it wont start unless VC++ is installed is because you have probably have checked the "As shared DLL" alternative in AppWizard. Then you'll need those files in the same dir as the exe to run a MFC app on another computer:
MFC42D.DLL
MFCO42D.DLL
MSVCRTD.DLL
------------------------------
©0d3 ©®4©k3® - That's me!
------------------------------
|
|
|
|
|
Make sure that if you are using shared DLL that you link to the Release versions of the DLL's.
Redistributing the debug dll's is a bad idea and may also be a violation of Microsoft's licence agreement.
Michael
|
|
|
|
|
Thanks for all the answers!
It is an MFC app and I'm using the release build so the program doesn't use any of the development dlls. I'm using two ActiveX controls, mediaplayer2 and MS Image Forms 2.0. My devenviroment is VC++ Pro.
Using the filemonitor program I can see that my program depends on MFC42.dll, MFC42LOC.dll, MSVCIRT.dll, OLE32.dll, OLEAUT32.dll, CLBCATQ.dll and MSVCRT.dll. Everything is successful when I load my program. I can't see anything wrong when I run the Regmonitor, the dependency walker v2.1 can't find anything wrong either.
The program just shuts down after having something to do with ~CLBCATQ.dll. I'm trying to run my program in W2k without VC++ installed. I know it works with VC++ installed.
I can't understand anything...? Any suggestions are welcome!
|
|
|
|
|
According to MSDN, having the ~CLBCATQ.dll present means that COM+ hasn't been installed correctly on your machine.
Are you using COM + services?
Michael
|
|
|
|
|
That's strange... No, I'm not using any COM+ services.
- Tobias
|
|
|
|
|