blob: f0289ef0d95aa1d454a7e094c0f5a817e2ba6634 [file] [log] [blame]
page.title=Printing Photos
parent.title=Printing Content
next.title=Printing HTML Documents
<div id="tb-wrapper">
<div id="tb">
<h2>This lesson teaches you to</h2>
<li><a href="#image">Print an Image</a></li>
Taking and sharing photos is one of the most popular uses for mobile devices. If your application
takes photos, displays them, or allows users to share images, you should consider enabling printing
of those images in your application. The <a href="{@docRoot}tools/support-library/index.html"
>Android Support Library</a> provides a convenient function for enabling image printing using a
minimal amount of code and simple set of print layout options.
<p>This lesson shows you how to print an image using the v4 support library {@link} class.</p>
<h2 id="image">Print an Image</h2>
<p>The Android Support Library {@link} class provides
a simple way to print of images. The class has a single layout option, {@link setScaleMode()}, which allows you to print with
one of two options:</p>
<li>{@link SCALE_MODE_FIT} - This
option sizes the image so that the whole image is shown within the printable area of the page.
<li>{@link SCALE_MODE_FILL} - This
option scales the image so that it fills the entire printable area of the page. Choosing this
setting means that some portion of the top and bottom, or left and right edges of the image is
not printed. This option is the default value if you do not set a scale mode.</li>
<p>Both scaling options for {@link
setScaleMode()} keep the existing aspect ratio of the image intact. The following code example
shows how to create an instance of the {@link} class, set the
scaling option, and start the printing process:</p>
private void doPhotoPrint() {
PrintHelper photoPrinter = new PrintHelper(getActivity());
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
photoPrinter.printBitmap("droids.jpg - test print", bitmap);
This method can be called as the action for a menu item. Note that menu items for actions that are
not always supported (such as printing) should be placed in the overflow menu. For more
information, see the <a href="{@docRoot}design/patterns/actionbar.html">Action Bar</a> design
<p>After the {@link printBitmap()} method is
called, no further action from your application is required. The Android print user interface
appears, allowing the user to select a printer and printing options. The user can then print the
image or cancel the action. If the user chooses to print the image, a print job is created and a
printing notification appears in the system bar.</p>
<p>If you want to include additional content in your printouts beyond just an image, you must
construct a print document. For information on creating documents for printing, see the
<a href="html-docs.html">Printing an HTML Document</a> or
<a href="custom-docs.html">Printing a Custom Document</a>