You cannot cast a control into
Bitmap
. You have to do different thing: copy a part of the screen from the bounding rectangle of the control. Most likely, you are using
System.Windows.Forms
and
System.Drawing
. If so, you can use
System.Drawing.Graphics.CopyFromScreen
:
Graphics.CopyFromScreen Method (Int32, Int32, Int32, Int32, Size) (System.Drawing)[
^].
To copy part of the screen into a bitmap, first create a bitmap instance of required size and obtain an instance of
System.Drawing.Graphics
which can be used to draw in this bitmap:
Graphics.FromImage Method (Image) (System.Drawing)[
^].
Another problem is:
GetPixel
is prohibitively slow. Instead, you have to use one of the methods
System.Drawing.Bitmap.LockBits
:
Bitmap.LockBits Method (Rectangle, ImageLockMode, PixelFormat) (System.Drawing)[
^].
Few words on the expected result: it's pretty obvious that RTF document, in a way, does not have its own pixel colors. Its rendering depends on the device, current layout of the bounding rectangle, system settings and other detail. If, say, you use just black text of white background, you will get several colors used for, in particular,
anti-aliasing and
ClearType effect. It makes me feel puzzled about the purpose of your question.
—SA