RichTextBox - Sending "zoomed" output to bitmap

This question is of a somewhat general nature, but I thought this group would most likely to have an answer. I have code that allows me to basically write the contents of a richtextbox to a bitmap (sending a EM_FORMATRANGE using SendMessage). This code works fine, but it always draws the text "normal size" regardless of the setting of ZoomFactor in the RichTextBox. How can I get the "zoomed" version of the text into a bitmap? Thanks in advance!

1 Reply

AD Administrator Syncfusion Team December 13, 2005 04:47 PM UTC

Hi Lori, Essential Diagram uses a similar approach for drawing its RichTextNode object. To achieve a zoomed effect on the rendered text, we apply a scaling transformation to the destination Graphics object, render the contents of the RichText to a separate bitmap graphics object and then use Graphics.DrawImage to copy the contents of the text bitmap onto the destination Graphics. The following outline should give you an idea about the approach that we use, // grfx is the destination graphics object // Apply a scaling transformation to the Graphics // using the zoom scale // For a 200% zoom Matrix zoomMtrx = new Matrix(2,0,0,2,0,0); grfx.Transform = zoomMtrx; // Create a bmp Graphics for the RichText control System.Drawing.Rectangle txtbounds; Bitmap textimage = new Bitmap(txtbounds.Width, txtbounds.Height); Graphics bmpgrfx = Graphics.FromImage(textimage); // Draw the RichText contents this.DrawRichText(bmpgrfx, this.richTextCtl.Rtf, false, txtbounds, txtbounds, this.BackgroundColor, System.Drawing.Rectangle.Empty, true, 100); bmpgrfx.Dispose(); // Now copy the contents of the text image onto the destination graphics object PointF[] destPoints; grfx.DrawImage( textimage, destPoints, new RectangleF( 0, 0, textimage.Width, textimage.Height), GraphicsUnit.Pixel, imgAttr ); textimage.Dispose(); grfx.ResetTransform(); grfx.Dispose() Hope this helps. Prakash Surendra Syncfusion Inc.,

Loader.
Up arrow icon