1topic "Draw"; 2[2 $$0,0#00000000000000000000000000000000:Default] 3[l288;i704;a17;O9;~~~.992;2 $$1,0#10431211400427159095818037425705:param] 4[a83;*R6 $$2,5#31310162474203024125188417583966:caption] 5[b83;*2 $$3,5#07864147445237544204411237157677:title] 6[b167;a42;C2 $$4,6#40027414424643823182269349404212:item] 7[b42;a42;2 $$5,5#45413000475342174754091244180557:text] 8[l288;a17;2 $$6,6#27521748481378242620020725143825:desc] 9[l321;t246;C@5;1 $$7,7#20902679421464641399138805415013:code] 10[b2503;2 $$8,0#65142375456100023862071332075487:separator] 11[*@(0.0.255)2 $$9,0#83433469410354161042741608181528:base] 12[t4167;C2 $$10,0#37138531426314131251341829483380:class] 13[l288;a17;*1 $$11,11#70004532496200323422659154056402:requirement] 14[i417;b42;a42;O9;~~~.416;2 $$12,12#10566046415157235020018451313112:tparam] 15[b167;C2 $$13,13#92430459443460461911108080531343:item1] 16[i288;a42;O9;C2 $$14,14#77422149456609303542238260500223:item2] 17[*@2$(0.128.128)2 $$15,15#34511555403152284025741354420178:NewsDate] 18[l321;*C$7;2 $$16,16#03451589433145915344929335295360:result] 19[l321;b83;a83;*C$7;2 $$17,17#07531550463529505371228428965313:result`-line] 20[l160;t4167;*C+117 $$18,5#88603949442205825958800053222425:package`-title] 21[{_}%EN-US 22[s2; Draw&] 23[s0; This article tries to describe view of the Draw object`'s role 24in the painting process.&] 25[s0; &] 26[s0; Please remember: Draw is not the raster image itself, much the 27less encoded in a particular image format. I believe you would 28do best to think about Draw as a channel or a toolbox interfacing 29the painting routine (a part of the program which wants to paint 30something; for the time being let`'s ignore the distinction between 31drawing vectors and rasters) to the actual `"canvas`" being painted 32onto. The main role of Draw is exactly to turn your logical drawing 33commands (e.g. `"draw a line`", `"draw a bit of text`", `"draw 34a raster image`" etc.) into something the output `"device`" can 35understand.&] 36[s0; &] 37[s0; Now, this is the general story. In reality there are basically 38two families of Draw`-related objects sharing many common traits. 39These are:&] 40[s0; &] 41[s0;i150;O2; raster`-oriented Draw objects: these normally include 42the Draw object in the Ctrl`::Paint override, the ViewDraw, the 43BackDraw, the ImageDraw `& ImageMaskDraw and sometimes PrintDraw.&] 44[s0; &] 45[s0;i150;O2; vector`-oriented Draw objects: DrawingDraw, WinMetaFileDraw 46and sometimes PrintDraw, and also (normally) PageDraw, PdfDraw 47and Report.&] 48[s0; &] 49[s0; Although some might prefer to explain the characteristics of 50the above objects in abstract terms (with multiple references 51to `"you don`'t need to know this and that`" :`-) ), I choose 52to be honest with you as to how they really work, because I believe 53that`'ll move you the farthest along the way.&] 54[s0; &] 55[s0; Actually the Draw is something like a semi`-intelligent painter 56with a plentiful palette of logical drawing objects; some of 57these are by nature vector`-oriented, like lines, rectangles, 58polygons etc., some are naturally rasterized, typically Images, 59some are a bit of both, especially text objects.&] 60[s0; &] 61[s0; Now, when the Draw receives a command to draw something (in 62U`+`+ terminology, a drawing operation, see the host of xxxOp 63methods in the declaration of Draw), the painter for the desired 64output device has to decide what to do with it. Typically, when 65the object is of the same type as the output medium (both are 66vector or raster), not much work has to be done. When the source 67(the drawing operation) is vector`-oriented and the output device 68is raster`-based, the vector object has to be rasterized.&] 69[s0; &] 70[s0; Typical raster`-based Draw objects are related to painting into 71windows and images; the Draw passed to Ctrl`::Paint by the U`+`+ 72windowing mechanism is such a case, as well as ViewDraw, BackDraw 73or ImageDraw and ImageMaskDraw. All these drawing objects use 74the MS Windows or X Windows mechanism called GDI to channel the 75drawing objects to the built`-in rasterizer which (perhaps using 76some graphic card accelerator in certain cases) ends up by modifying 77the desired pixels on the target device (the Ctrl area or the 78Image).&] 79[s0; &] 80[s0; By calling the other Draw classes `"vector`-based`" I don`'t 81mean they cannot cope with raster data. I am perhaps a little 82abusing the standard notion of the word to emphasize the fact 83that the latter group can manipulate vector objects directly, 84without rasterizing them first. So, for instance, DrawingDraw 85and WinMetaFileDraw are used to generate a serialized representation 86of the executed sequence of drawing operations, which can be 87later `"played back`" thus reproducing the original drawing.&] 88[s0; &] 89[s0; Notice that in the above cases there is no actual `"canvas`" 90to be painted onto. Both DrawingDraw and WinMetaFileDraw merely 91maintain a data stream which is used to record the individual 92drawing operations (coming into Draw via the xxxOp member functions) 93without actually caring about what is being drawn very much. 94This is also the reason why you cannot read rasterized data from 95such types of Draw: if you call DrawToImage, for instance, for 96a DrawingDraw, it is sure to fail. But then, even if you call 97DrawToImage for a ViewDraw, you cannot always count on getting 98the correct image, because in situations when a portion of the 99window is obscured by another application, you`'ll get a snapshot 100of this other application and not your window.&] 101[s0; &] 102[s0; The main advantage of DrawingDraw compared with ImageDraw (if 103we choose to see these two classes as two different means for 104creating a drawing which can be stored afterwards, perhaps to 105a file or a program cache) is that it can later (upon play`-back) 106reproduce the original vector operations (like lines or polygons) 107exactly even when size of `"painting`" is rescaled, without blocky 108artifacts inevitable in rasters.&] 109[s0; &] 110[s0; To sum the above into a few practical guidelines, please try 111to remember the following:&] 112[s0; &] 113[s0;i150;O2; To create a recording of an image, use DrawingDraw or 114ImageDraw (see the above distinction between these two). E.g.&] 115[s0; &] 116[s7; DrawingDraw ddraw(100, 100);&] 117[s7; myobject.Paint(ddraw);&] 118[s7; Drawing dwg `= ddraw.GetResult(); // dwg is the output recording&] 119[s7; &] 120[s7; Image img(100, 100);&] 121[s7; ImageDraw idraw(img);&] 122[s7; myobject.Paint(idraw);&] 123[s7; idraw.Close();&] 124[s7; // now the Image has been modified by the myobject`'s drawing&] 125[s7; operations and can be e.g. saved to disk&] 126[s0; &] 127[s0;i150;O2; When using DrawToImage, you should take care of the 128above limitations. In particular, it is not always wise to use 129DrawToImage on a Draw which is not entirely under your control. 130To make the long story short, you`'re all right with ImageDraw 131and perhaps with BackDraw, but scarcely with anything else, becauses 132in most cases you cannot be sure what you`'ll get (e.g. with 133ViewDraw or PrintDraw). In certain cases you can be sure you`'ll 134get nothing at all (e.g. with DrawingDraw).&] 135[s0; &] 136[s0;i150;O2; As concerns the difference between an Image and an AlphaArray, 137logically there`'s none (both represent masked raster images). 138Physically there is a lot of difference (you can view this difference 139as more or less optimization`-related), because the AlphaArray 140is a physical matrix of pixels maintained directly by the application, 141whereas an Image is (at least sometimes) a logical bitmap object 142maintained by the Windows system (this is especially important 143in X Windows, because the AlphaArray is stored on the client, 144whereas Images are stored in the X Server). Another difference 145is that you can create an AlphaArray in any pixel format you 146want, but the supported pixel formats of Images are (or can be) 147limited by the properties of your windowing system.&] 148[s0; &] 149[s0;i150;O2; As concerns image storage in the various standard formats 150(like jpg, png or gif), again these formats belong neither to 151the Draw object, nor to the Image object. It`'s best to see the 152ImageEncoder`'s as mere data processors which receive a raster 153input (an AlphaArray or an Image) and produce an encoded linearized 154image as their output (this is obviously the encoding phase corresponding 155to the Save`-routines; with the Load`-routines, the situation 156is vice versa). Therefore, as soon as you have an Image (or an 157AlphaArray), you can Save it in any format you like. Similarly, 158you can take an image file in one of the standard formats and 159read it into an AlphaArray or an Image.&] 160[s0; ]]