haiku-website/static/legacy-docs/bebook/BBitmapStream_Overview.html

49 lines
8.8 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>The Be Book - System Overview - The Translation Kit</title><link rel="stylesheet" href="be_book.css" type="text/css" media="all" /><link rel="shortcut icon" type="image/vnd.microsoft.icon" href="./images/favicon.ico" /><!--[if IE]>
<link rel="stylesheet" type="text/css" href="be_book_ie.css" />
<![endif]--><meta name="generator" content="DocBook XSL Stylesheets V1.73.2" /><meta name="keywords" content="Access, BeOS, BeBook, API" /><link rel="start" href="index.html" title="The Be Book" /><link rel="up" href="TheTranslationKit_Overview.html" title="The Translation Kit" /><link rel="prev" href="TheTranslationKit_Introduction.html" title="Introduction" /><link rel="next" href="BTranslationUtils_Overview.html" title="BTranslationUtils" /></head><body><div id="header"><div id="headerT"><div id="headerTL"><a accesskey="p" href="TheTranslationKit_Introduction.html" title="Introduction"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a accesskey="u" href="TheTranslationKit_Overview.html" title="The Translation Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a accesskey="n" href="BTranslationUtils_Overview.html" title="BTranslationUtils"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="headerTR"><div id="navigpeople"><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div><div class="navigboxed" id="navigindex"><a accesskey="i" href="ClassIndex.html" title="Index">I</a></div><div class="navigboxed" id="naviglang" title="English">en</div></div><div id="headerTC">The Be Book - System Overview - The Translation Kit</div></div><div id="headerB">Prev: <a href="TheTranslationKit_Introduction.html">Introduction</a>  Up: <a href="TheTranslationKit_Overview.html">The Translation Kit</a>  Next: <a href="BTranslationUtils_Overview.html">BTranslationUtils</a></div><hr /></div><div class="section"><div xmlns="" xmlns:d="http://docbook.org/ns/docbook" class="titlepage"><div><div xmlns:d="http://docbook.org/ns/docbook"><h2 xmlns="http://www.w3.org/1999/xhtml" class="title"><a id="BBitmapStream_Overview"></a>BBitmapStream</h2></div></div></div><a id="id620537" class="indexterm"></a><p><a class="link" href="BBitmapStream.html" title="BBitmapStream"><code class="classname">BBitmapStream</code></a>
allows for the easy conversion of a translator bitmap, the
default Translation Kit bitmap format, to a
<a class="link" href="BBitmap.html" title="BBitmap"><code class="classname">BBitmap</code></a>.
It's a very limited subclass of
<a class="link" href="BPositionIO.html" title="BPositionIO"><code class="classname">BPositionIO</code></a>
capable only of reading and writing translator
bitmaps; performing i/o on the object with other types of data can yield
strange results. The main attraction of the class is the
<a class="link" href="BBitmapStream.html#BBitmapStream_DetachBitmap" title="DetachBitmap()"><code class="methodname">DetachBitmap()</code></a>
method, which returns the contents of the object as a
<a class="link" href="BBitmap.html" title="BBitmap"><code class="classname">BBitmap</code></a>.</p><p>Most of the time, you won't need to use
<a class="link" href="BBitmapStream.html" title="BBitmapStream"><code class="classname">BBitmapStream</code></a> directly;
<a class="link" href="BTranslationUtils.html" title="BTranslationUtils"><code class="classname">BTranslationUtils</code></a>
contains the functionality required to load images from
files, resources, or general BPositionIOs into
<a class="link" href="BBitmap.html" title="BBitmap"><code class="classname">BBitmap</code></a>s.</p><p>The following snippet illustrates typical usage of
<a class="link" href="BBitmapStream.html" title="BBitmapStream"><code class="classname">BBitmapStream</code></a>
sans proper error checking:</p><pre class="programlisting example cpp"><span class="type">BBitmap *</span><code class="function">FetchBitmap</code>(<span class="type">char *</span><code class="parameter">filename</code>)
{
<code class="classname">BFile</code> <code class="varname">file</code>(<code class="parameter">filename</code>, <code class="constant">B_READ_ONLY</code>);
<span class="type">BTranslatorRoster *</span><code class="varname">roster</code> = <code class="classname">BTranslatorRoster</code>::<code class="methodname">Default</code>();
<code class="classname">BBitmapStream</code> <code class="varname">stream</code>;
<span class="type">BBitmap *</span><code class="varname">result</code> = <code class="constant">NULL</code>;
if (<code class="varname">roster</code>-&gt;<code class="methodname">Translate</code>(&amp;<code class="varname">file</code>, <code class="constant">NULL</code>, <code class="constant">NULL</code>, &amp;<code class="varname">stream</code>,
<code class="constant">B_TRANSLATOR_BITMAP</code>) &lt; <code class="constant">B_OK</code>)
return <code class="constant">NULL</code>;
<code class="varname">stream</code>.<code class="methodname">DetachBitmap</code>(&amp;<code class="varname">result</code>);
return <code class="varname">result</code>;
}</pre><p>You can also initialize the class with a
<a class="link" href="BBitmap.html" title="BBitmap"><code class="classname">BBitmap</code></a> and use it as input to
<a class="link" href="BTranslatorRoster.html#BTranslatorRoster_Translate" title="Translate()"><code class="methodname">BTranslatorRoster::Translate()</code></a>
to save it in a different format:</p><pre class="programlisting example cpp"><span class="type">void</span> <code class="function">StoreTranslatorBitmap</code>(<span class="type">BBitmap *</span><code class="parameter">bitmap</code>, <span class="type">char *</span><code class="parameter">filename</code>,
<span class="type">uint32</span> <code class="parameter">type</code>)
{
<span class="type">BTranslatorRoster *</span><code class="varname">roster</code> = <code class="classname">BTranslatorRoster</code>::<code class="methodname">Default</code>();
<code class="classname">BBitmapStream</code> <code class="varname">stream</code>(<code class="parameter">bitmap</code>); // init with contents of bitmap
<code class="classname">BFile</code> <code class="varname">file</code>(<code class="parameter">filename</code>, <code class="constant">B_CREATE_FILE</code> | <code class="constant">B_WRITE_ONLY</code>);
<code class="varname">roster</code>-&gt;<code class="methodname">Translate</code>(&amp;<code class="varname">stream</code>, <code class="constant">NULL</code>, <code class="constant">NULL</code>, &amp;<code class="varname">file</code>, <code class="parameter">type</code>);
}</pre></div><div id="footer"><hr /><div id="footerT">Prev: <a href="TheTranslationKit_Introduction.html">Introduction</a>  Up: <a href="TheTranslationKit_Overview.html">The Translation Kit</a>  Next: <a href="BTranslationUtils_Overview.html">BTranslationUtils</a> </div><div id="footerB"><div id="footerBL"><a href="TheTranslationKit_Introduction.html" title="Introduction"><img src="./images/navigation/prev.png" alt="Prev" /></a> <a href="TheTranslationKit_Overview.html" title="The Translation Kit"><img src="./images/navigation/up.png" alt="Up" /></a> <a href="BTranslationUtils_Overview.html" title="BTranslationUtils"><img src="./images/navigation/next.png" alt="Next" /></a></div><div id="footerBR"><div><a href="http://www.haiku-os.org"><img src="./images/People_24.png" alt="haiku-os.org" title="Visit The Haiku Website" /></a></div><div class="navighome" title="Home"><a accesskey="h" href="index.html"><img src="./images/navigation/home.png" alt="Home" /></a></div></div><div id="footerBC"><a href="http://www.access-company.com/home.html" title="ACCESS Co."><img alt="Access Company" src="./images/access_logo.png" /></a></div></div></div><div id="licenseFooter"><div id="licenseFooterBL"><a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/" title="Creative Commons License"><img alt="Creative Commons License" style="border-width:0" src="https://licensebuttons.net/l/by-nc-nd/3.0/88x31.png" /></a></div><div id="licenseFooterBR"><a href="./LegalNotice.html">Legal Notice</a></div><div id="licenseFooterBC"><span id="licenseText">This work is licensed under a
<a rel="license" href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Creative
Commons Attribution-Non commercial-No Derivative Works 3.0 License</a>.</span></div></div></body></html>