PrintHelper
public final class PrintHelper
Helper for printing bitmaps.
Summary
Nested types |
|---|
public interface PrintHelper.OnPrintFinishCallbackCallback for observing when a print operation is completed. |
Constants |
|
|---|---|
static final int |
COLOR_MODE_COLOR = 2this is a color image (default) |
static final int |
this is a black and white image |
static final int |
Print the image in landscape orientation (default). |
static final int |
Print the image in portrait orientation. |
static final int |
SCALE_MODE_FILL = 2image will fill the paper and be cropped (default) |
static final int |
SCALE_MODE_FIT = 1image will be scaled but leave white space |
Public constructors |
|---|
PrintHelper(@NonNull Context context)Constructs the PrintHelper that can be used to print images. |
Public methods |
|
|---|---|
int |
Gets the color mode with which the image will be printed. |
int |
Gets whether the image will be printed in landscape or portrait. |
int |
Returns the scale mode with which the image will fill the paper. |
void |
printBitmap(@NonNull String jobName, @NonNull Bitmap bitmap)Prints a bitmap. |
void |
printBitmap(@NonNull String jobName, @NonNull Uri imageFile)Prints an image located at the Uri. |
void |
printBitmap(Prints a bitmap. |
void |
printBitmap(Prints an image located at the Uri. |
void |
setColorMode(int colorMode)Sets whether the image will be printed in color (default) |
void |
setOrientation(int orientation)Sets whether the image will be printed in landscape |
void |
setScaleMode(int scaleMode)Selects whether the image will fill the paper and be cropped |
static boolean |
Gets whether the system supports printing. |
Constants
COLOR_MODE_COLOR
public static final int COLOR_MODE_COLOR = 2
this is a color image (default)
COLOR_MODE_MONOCHROME
public static final int COLOR_MODE_MONOCHROME = 1
this is a black and white image
ORIENTATION_LANDSCAPE
public static final int ORIENTATION_LANDSCAPE = 1
Print the image in landscape orientation (default).
ORIENTATION_PORTRAIT
public static final int ORIENTATION_PORTRAIT = 2
Print the image in portrait orientation.
SCALE_MODE_FILL
public static final int SCALE_MODE_FILL = 2
image will fill the paper and be cropped (default)
SCALE_MODE_FIT
public static final int SCALE_MODE_FIT = 1
image will be scaled but leave white space
Public constructors
Public methods
getColorMode
public int getColorMode()
Gets the color mode with which the image will be printed.
| Returns | |
|---|---|
int |
The color mode which is one of |
getOrientation
public int getOrientation()
Gets whether the image will be printed in landscape or portrait.
| Returns | |
|---|---|
int |
The page orientation which is one of |
getScaleMode
public int getScaleMode()
Returns the scale mode with which the image will fill the paper.
| Returns | |
|---|---|
int |
The scale Mode: |
printBitmap
public void printBitmap(@NonNull String jobName, @NonNull Bitmap bitmap)
Prints a bitmap.
printBitmap
public void printBitmap(@NonNull String jobName, @NonNull Uri imageFile)
Prints an image located at the Uri. Image types supported are those of android.graphics.BitmapFactory.decodeStream(java.io.InputStream)
| Parameters | |
|---|---|
@NonNull String jobName |
The print job name. |
@NonNull Uri imageFile |
The |
| Throws | |
|---|---|
java.io.FileNotFoundException |
if |
printBitmap
public void printBitmap(
@NonNull String jobName,
@NonNull Bitmap bitmap,
@Nullable PrintHelper.OnPrintFinishCallback callback
)
Prints a bitmap.
printBitmap
public void printBitmap(
@NonNull String jobName,
@NonNull Uri imageFile,
@Nullable PrintHelper.OnPrintFinishCallback callback
)
Prints an image located at the Uri. Image types supported are those of android.graphics.BitmapFactory.decodeStream(java.io.InputStream)
| Parameters | |
|---|---|
@NonNull String jobName |
The print job name. |
@NonNull Uri imageFile |
The |
@Nullable PrintHelper.OnPrintFinishCallback callback |
Optional callback to observe when printing is finished. |
| Throws | |
|---|---|
java.io.FileNotFoundException |
if |
setColorMode
public void setColorMode(int colorMode)
Sets whether the image will be printed in color (default) COLOR_MODE_COLOR or in back and white COLOR_MODE_MONOCHROME.
| Parameters | |
|---|---|
int colorMode |
The color mode which is one of |
setOrientation
public void setOrientation(int orientation)
Sets whether the image will be printed in landscape ORIENTATION_LANDSCAPE (default) or portrait ORIENTATION_PORTRAIT.
| Parameters | |
|---|---|
int orientation |
The page orientation which is one of |
setScaleMode
public void setScaleMode(int scaleMode)
Selects whether the image will fill the paper and be cropped SCALE_MODE_FIT or whether the image will be scaled but leave white space SCALE_MODE_FILL.
| Parameters | |
|---|---|
int scaleMode |
systemSupportsPrint
public static boolean systemSupportsPrint()
Gets whether the system supports printing.
| Returns | |
|---|---|
boolean |
True if printing is supported. |