diff options
author | scuri <scuri> | 2011-08-16 18:21:44 +0000 |
---|---|---|
committer | scuri <scuri> | 2011-08-16 18:21:44 +0000 |
commit | 51f26b3868b62f70f49e11dab933b4778ffa84c6 (patch) | |
tree | 579eafa29c20daabd6189ab0e2d11a0931bb7296 /html/en/samples.html | |
parent | 419293cfcee27e46525b9f1e94e7da102b7c7d00 (diff) |
*** empty log message ***
Diffstat (limited to 'html/en/samples.html')
-rw-r--r-- | html/en/samples.html | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/html/en/samples.html b/html/en/samples.html index e088f3b..accd638 100644 --- a/html/en/samples.html +++ b/html/en/samples.html @@ -39,9 +39,27 @@ <pre><code>cdCanvas* canvas = cdCreateCanvasf(CD_IMAGERGB, "%dx%d", width, height); </code>cd<code>Canvas</code>LineStyle(<code>canvas, </code>CD_DASHED); cd<code>Canvas</code>Line(<code>canvas, </code>10, 10, 50, 50); -unsigned char* red = cdCanvasGetAttribute(canvas, "REDIMAGE"); -// do something with the raw image data -cdKillCanvas(canvas); +cdKillCanvas(canvas); </pre> +<p>To save the contents of the CD_IMAGERGB canvas in a file using IM, after +drawing and before destroying the canvas do:</p> +<pre>unsigned char* data = cdCanvasGetAttribute(canvas, "REDIMAGE"); // Also a pointer to the full buffer +imImage* image = <strong>imImageInit</strong>(width, height, IM_RGB, IM_BYTE, data, NULL, 0); +// Can use also IM_RGB|IM_ALPHA is canvas has support for alpha +<strong>imFileImageSave</strong>(file_name, "PNG", image); +image->data[0] = NULL; // to avoid duplicate memory release +<strong>imImageDestroy</strong>(image);</pre> +<p>Or using another approach:</p> +<pre>imImage* image = <strong>imImageCreate</strong>(width, height, IM_RGB, IM_BYTE); +// Can also call <strong>imImageAddAlpha</strong> if alpha support is wanted + +<code>cdCanvas* canvas = cdCreateCanvasf(CD_IMAGERGB, "%dx%d %p %p %p", width, height, + image->data[0], image->data[1], image->data[2]); +</code>cd<code>Canvas</code>LineStyle(<code>canvas, </code>CD_DASHED); +cd<code>Canvas</code>Line(<code>canvas, </code>10, 10, 50, 50); +cdKillCanvas(canvas); + +<strong>imFileImageSave</strong>(file_name, "PNG", image); +<strong>imImageDestroy</strong>(image); </pre> |