1. Printing Graphics - .bmps
- Posted by tweezer Jun 05, 2011
- 1220 views
Hello!
OK... I have created a program that generates a barcode label. I have a RichEdit box, whi, "on Paint" draws the barcode image from a .bmp file, then adds some text from variables. The image and text paint up nicely in the RE window when I run the program.
I want to print that RichEdit... I am using win32lib's "printRichTextPages". However, my image does not print! (not a printer issue.)
Can anyone give some guidance on how to set up a window with dynamic text and graphics that I can print?
Thanks in advance for any advice! T.
2. Re: Printing Graphics - .bmps
- Posted by ghaberek (admin) Jun 05, 2011
- 1225 views
Unfortunately you cannot do things in the way. Since you are manually painting graphics onto the control, there is no way to make it actually "stick" in the control to be printed later. It would also be a little difficult to get the image to stay inline with the text when the window is scrolled. Instead, you have to tell the control to insert the image within its own text buffer so it displays in-line.
Using Win32Lib, this would be accomplished using a series of RTF control codes and putStream(). However, I've never had good luck getting that to work correctly. I've gone so far as to create a rich text file in WordPad, then load the contents of the file into a Win32Lib RichEdit using putStream() and everything shows up - except the images!
I suggest using wxEuphoria and its custom wxRichTextCtrl instead. Currently wxEuphoria does not have support for wxRichTextPrinting, but I will get that implemented soon. It will make printing super-easy.
-Greg
include "wxeu/wxeud.e" without warning object void constant wxID_INSERT = new_id(), frmMain = create( wxFrame, {0, -1, "RichText Demo", -1, -1, 640, 480} ), mbrMain = create( wxMenuBar, {frmMain} ), mnuFile = create( wxMenu, {mbrMain, "&File"} ), mnuFile_Insert = create( wxMenuItem, {mnuFile, wxID_INSERT, "&Insert Image..."} ), rchEdit = create( wxRichTextCtrl, {frmMain} ), $ procedure menu_handler( atom this, atom event_type, atom id, atom event ) if id = wxID_INSERT then sequence filename = file_selector( frmMain, "Insert", { "", -- path "", -- file "", -- extension "All Image Files (*.bmp;*.gif;*.jpg;*.png)" & "|*.bmp;*.gif;*.jpg;*.png" -- wildcard }, wxOPEN+wxFILE_MUST_EXIST ) if length( filename ) = 0 then break end if atom size = get_size( filename ) begin_suppress_undo( rchEdit ) begin_bold( rchEdit ) append_text( rchEdit, filename ) end_bold( rchEdit ) append_text( rchEdit, sprintf(" (%d KB)", floor(size / 1024)) ) line_break( rchEdit ) -- typical method, for adding images directly from files write_image_from_file( rchEdit, filename, wxBITMAP_TYPE_ANY ) line_break( rchEdit ) end_suppress_undo( rchEdit ) -- round-about method, useful for adding images from memory -- atom bmp = create( wxBitmap, {BM_FROM_FILE, filename, wxBITMAP_TYPE_ANY} ) -- atom img = convert_to_image( bmp ) -- write_image( rchEdit, img, wxBITMAP_TYPE_PNG ) end if end procedure set_event_handler( frmMain, -1, wxEVT_COMMAND_MENU_SELECTED, routine_id("menu_handler") ) wxMain( frmMain )
3. Re: Printing Graphics - .bmps
- Posted by tweezer Jun 05, 2011
- 1187 views
Greg,
Many thanks for your response! I will look at wxEuphoria for a solution.
In the meantime, I found this solution: - First I used an MLE instead of Rich Text. - Paint it up with my bitmaps and text labels. - I can save the contents of the MLE to a bitmap using copyToBitmapFile. Now I have one bitmap which includes all the parts. - Then I can create a new window with just a bitmap, and load my bitmap from the file. - From there I can send it to the printer and it works. For these last two steps I am following the win32lib example "BitmapPrint.exw".
Kind of a workaround, but it works for now.
THanks again Greg!
4. Re: Printing Graphics - .bmps
- Posted by ghaberek (admin) Jun 05, 2011
- 1166 views
I think I better understand what you're trying to do now. Try creating a Pixmap and draw your text and barcode onto that. Then just copyBlt() the pixmap to your window during its w32HPaint event. Then when you need to do your printing, just copyBlt() the pixmap again to the Printer instead.
This method is commonly known as "double buffering"; albeit a simple example of it.
-Greg