Printing to a graphics file

Hi,

I have an MFC application that displays a picture (scrolled), and prints it. I would like, however, to make it also create a graphics file, copy of what would be on the printer. I would also like to open this file later on and print it. What is the approach?

Thank you.
LVL 1
kerznerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

UandICommented:
Try to write the information to a CMetaFileDC instead to the printer device context. With CopyMetaFile you can then write it to a file.

I suggest that you see the documentation on this and try to find sample code from MSDN.

Another way would be to transform your picture into a standard bitmap format and write it to a file with your own code. This would allow you to open the file with any graphic editor (for example paintbrush).

I hope this helps you somehow.
0
kerznerAuthor Commented:
Thank you, I would accept the answer as complete, if I knew how to form my own bitmaps.
Does anybody know a good library? Or for gif for that matter.

Sincerely yours.
0
stu32934Commented:
My be completely irrelevent but anyway...I've created a gif filter. I based it on GIFLIB and attapted it to handle multiple layered gifs. Have a look at:

http://www.tuxedo.org/~esr/giflib/doc/index.html
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

UandICommented:
I used the following code to prepare my own bitmaps:

//Create a 24-bit-per-pixel surface
HBITMAP Create24BPPDIBSection(HDC hDC, int iWidth, int iHeight)
{
      BITMAPINFO      bmi;
      HBITMAP            hbm;
      LPBYTE            pBits;

      //Initialize to 0s
      ZeroMemory(&bmi, sizeof(bmi));

      //Initialize header
      bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
      bmi.bmiHeader.biWidth = iWidth;
      bmi.bmiHeader.biHeight = iHeight;
      bmi.bmiHeader.biPlanes = 1;
      bmi.bmiHeader.biBitCount = 24;
      bmi.bmiHeader.biCompression = BI_RGB;

      //Create the surface
      hbm = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS, (void**)&pBits, NULL, 0);
      return(hbm);
}

Hope it helps
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kerznerAuthor Commented:
Thank you,

I think the gif libraries and bmp code will solve my problem completely. Of course, one has to delve in it, but if I understand correctly that I can translate my MoveTo() and LineTo() calls to the created image instead of the screen, then I would consider this questions closed.

Thanks again. Sincerely,
Mark Kerzner
0
kerznerAuthor Commented:
I had to accept only one answer as final, but I would also like to give credit to stu32934.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.