Symbian3/SDK/Source/GUID-A3EBB297-1494-579C-83D5-8FDBBD01B674.dita
author Dominic Pinkman <Dominic.Pinkman@Nokia.com>
Wed, 31 Mar 2010 11:11:55 +0100
changeset 7 51a74ef9ed63
child 8 ae94777fff8f
permissions -rw-r--r--
Week 12 contribution of API Specs and fix SDK submission
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
     1
<?xml version="1.0" encoding="utf-8"?>
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
     2
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
     3
<!-- This component and the accompanying materials are made available under the terms of the License 
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
     4
"Eclipse Public License v1.0" which accompanies this distribution, 
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
     5
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
     6
<!-- Initial Contributors:
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
     7
    Nokia Corporation - initial contribution.
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
     8
Contributors: 
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
     9
-->
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    10
<!DOCTYPE concept
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    11
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    12
<concept xml:lang="en" id="GUID-A3EBB297-1494-579C-83D5-8FDBBD01B674"><title>Drawing Bitmaps</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>This topic provides example code that demonstrates blitting a bitmap to the screen, blitting a rectangular piece of a bitmap to the screen and blitting a bitmap under a mask. </p> <p>These examples assume that <codeph>bitmap</codeph> is a pointer to a valid <codeph>CFbsBitmap</codeph> object. </p> <section><title>Bitmap block transfer</title> <p>Use <codeph>CBitmapContext::BitBlt()</codeph> to blit a <codeph>CFbsBitmap</codeph> to the screen. </p> <codeblock id="GUID-C40381A2-3729-5606-824F-7208421C76C2" xml:space="preserve">// draw the bitmap using bitmap block transfer
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    13
TPoint pos(50,50);
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    14
gc.BitBlt(pos, bitmap);</codeblock> </section> <section><title>Block transfer of a rectangular piece of a bitmap</title> <p>You can blit a rectangular piece of a bitmap to the screen. </p> <codeblock id="GUID-F216FE85-C2B4-586B-86D1-F6C859FA9891" xml:space="preserve">...
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    15
// set a rectangle for the top-left quadrant of the source bitmap
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    16
TSize bmpSizeInPixels=bitmap-&gt;SizeInPixels();
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    17
TSize bmpPieceSize(bmpSizeInPixels.iWidth/2,bmpSizeInPixels.iHeight/2);
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    18
TRect bmpPieceRect(TPoint(0,0),bmpPieceSize); 
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    19
    
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    20
// blit only the piece of the bitmap indicated by bmpPieceRect
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    21
TPoint pos(100,100);
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    22
gc.BitBlt(pos, bitmap, bmpPieceRect);</codeblock> </section> <section id="GUID-22430013-D8A8-5A09-8DD9-D95A6EF00B2D"><title>Masked bitmap block transfer</title> <p>Masks can be used to select which parts of a bitmap are drawn by <codeph>CBitmapContext::BitBltMasked()</codeph>. </p> <p>Masks can be used to not display pixels of the source bitmap if their corresponding mask pixel is black, or, alternatively, where the mask is white (called an inverted mask). </p> <p>The following figure shows successively a source bitmap, a mask, and the outcome when they are blitted with <codeph>BitBltMasked()</codeph>. </p> <fig id="GUID-425B6A42-6B3B-5FE4-BDD6-59CD7E695C4A"><image href="GUID-D1E80B1B-FBFD-5FBC-981C-E2D04A02EF41_d0e208830_href.png" placement="inline"/></fig> <codeblock id="GUID-8D967F91-A768-5DA7-A7D7-D5CA2D40B8D9" xml:space="preserve">// Load the mask bitmap, just like any other
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    23
CFbsBitmap* maskBitmap = new (ELeave) CFbsBitmap();
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    24
CleanupStack::PushL(maskBitmap);
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    25
User::LeaveIfError(maskBitmap-&gt;
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    26
  Load(multiBitmapFile,EMbmGrbmap2Smilmask));
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    27
    
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    28
// Calculate rectangle for the whole bitmap
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    29
TRect bmpPieceRect(TPoint(0,0),bitmap-&gt;SizeInPixels());
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    30
    
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    31
// Blit using a masking bitmap, with no inversion
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    32
gc.BitBltMasked(TPoint(50,50),bitmap,bmpPieceRect,maskBitmap,EFalse);
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    33
    
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    34
...
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    35
// clean up
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    36
CleanupStack::PopAndDestroy();
51a74ef9ed63 Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff changeset
    37
</codeblock> <p><b>Notes </b> </p> <ul><li id="GUID-4CDB8020-D42D-517D-BA3A-2D6FDD2DEA33"><p>Unlike with an ordinary <codeph>BitBlit()</codeph>, with <codeph>BitBltMasked()</codeph> you always have to specify what part of the bitmap to display: here we just set <codeph>bmpPieceRect</codeph> so that the whole bitmap is displayed. </p> </li> <li id="GUID-67FFCC84-B364-50DF-ACDA-54FF865FB423"><p>If the mask bitmap is smaller than the source bitmap, then it is tiled across the bitmap. </p> </li> <li id="GUID-A2A17DA3-5B03-56EF-B5FE-E6C8837F26F6"><p>For an inverted mask, set the last argument to <codeph>BitBltMasked()</codeph> to <codeph>ETrue</codeph>. </p> </li> </ul> </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>