Symbian3/SDK/Source/GUID-4BB03B97-9AD0-50D0-AAE5-B7AB2415716E.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Tue, 20 Jul 2010 12:00:49 +0100
changeset 13 48780e181b38
parent 0 89d6a7a84779
permissions -rw-r--r--
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept xml:lang="en" id="GUID-4BB03B97-9AD0-50D0-AAE5-B7AB2415716E"><title>Drawing Reduced and Enlarged Bitmaps</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>This topic provides examples of using <codeph>CGraphicsContext::DrawBitmap()</codeph> to draw a bitmap that is stretched or compressed. </p> <p>The bitmap blitting functions of the bitmapped graphics context (<codeph>CBitmapContext</codeph>) cannot be used to perform scaling of the bitmap. They always draws the bitmap using its dimensions in pixels. The overloaded GDI <codeph>CGraphicsContext::DrawBitmap()</codeph> function, however, can be used to draw a bitmap that is: </p> <ul><li id="GUID-D3E2B3CE-2E9E-521B-8B5E-E514B37ADF05"><p>stretched or compressed to a set size in twips </p> </li> <li id="GUID-B289040F-362F-57FE-BCDE-F60D573DB925"><p>stretched and/or compressed to fit a given rectangle. </p> </li> </ul> <p> <b>Note</b>: <codeph>DrawBitmap()</codeph> is slower than <codeph>BitBlt()</codeph>. You should therefore use <codeph>BitBlt()</codeph> in preference wherever possible. </p> <p>These examples assume that <codeph>bitmap</codeph> is a pointer to a valid <codeph>CFbsBitmap</codeph> object. </p> <section><title>Draw a bitmap at a set size in twips</title> <p>A bitmap can have a real world size in twips set for it, and be drawn scaled to that size. </p> <ol id="GUID-B38123EB-5AA5-5FEB-BBDC-0B89A49E7602"><li id="GUID-0C8F50C1-BF59-5D1F-BB4C-6F86A0FAA2E2"><p>Construct a <codeph>TSize</codeph> with the required dimensions in twips. </p> </li> <li id="GUID-CF58B6F6-B983-5C17-BFFB-8971E6C1E901"><p>Set the size of the bitmap using <codeph>CFbsBitmap::SetSizeInTwips()</codeph>. The default size in twips of a bitmap when loaded is <codeph>(0,0)</codeph>. </p> </li> <li id="GUID-395B3BAE-ECE4-5AE8-A275-27F8ED2785A9"><p>Draw the bitmap using <codeph>DrawBitmap()</codeph>  </p> </li> </ol> <codeblock id="GUID-C7B72F4D-25C3-5D7C-848B-8F5359F7D40C" xml:space="preserve">// Set twips size 
TSize bmpSizeInTwips(2000,2000);
bitmap-&gt;SetSizeInTwips(bmpSizeInTwips);
gc.DrawBitmap(TPoint(50,50), bitmap);</codeblock> </section> <section><title>Draw a bitmap in a given rectangle</title> <p> <codeph>DrawBitmap()</codeph> can also draw a bitmap by stretching it to fit a given rectangle. </p> <codeblock id="GUID-5278E9D2-8276-590D-9E26-BFB73DBA7096" xml:space="preserve">// Draw bitmap stretched from the origin to 100,100
TRect rect(0,0,100,100);
gc.DrawBitmap(rect, bitmap);</codeblock> </section> </conbody><related-links><link href="GUID-AFE8A9CC-E026-5396-8E0C-616338B5F5C3.dita"><linktext>BitGDI Tutorials</linktext> </link> <link href="GUID-EAAD1719-C02C-5705-A5C3-993E36441BE6.dita"><linktext>BitGDI Component</linktext> </link> </related-links></concept>