Я использую приведенный ниже код для отправки команды на принтер. Проблема здесь в том, что он должен взять изображение и отправить файл в временную папку. Этот файл должен быть отправлен на принтер и распечатан. но временная папка не создается и не является файлом. Вы можете помочь с этим?
void printCanvasExample ()
{
// создаем холст для рендеринга
Картинка картинка = новая картинка ();
Canvas c = picture.beginRecording (240, 240);
// fill background with WHITE
c.drawRGB( 0xFF, 0xFF, 0xFF );
// draw text
Paint p = new Paint();
Typeface font = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
p.setTextSize( 18 );
p.setTypeface( font );
p.setAntiAlias(true);
Rect textBounds = new Rect();
p.getTextBounds( HELLO_WORLD, 0, HELLO_WORLD.length(), textBounds );
int x = (c.getWidth() - (textBounds.right-textBounds.left)) / 2;
int y = (c.getHeight() - (textBounds.bottom-textBounds.top)) / 2;
c.drawText( HELLO_WORLD, x, y, p );
// draw icon
Bitmap icon = BitmapFactory.decodeResource( getResources(), R.drawable.icon );
c.drawBitmap( icon, 0, 0, null );
// stop drawing
picture.endRecording();
// queue canvas for printing
File f = PrintUtils.saveCanvasPictureToTempFile( picture );
if( f != null )
{
PrintUtils.queuePictureStreamForPrinting( this, f );
}
else
{
new AlertDialog.Builder(this).setTitle("Argh").setMessage("Watch out!").setNeutralButton("Close", null).show();
}
}
Код для создания временной папки в PrintUtils.java:
общедоступный статический файл saveCanvasPictureToTempFile (изображение рисунка)
{
Файл tempFile = null;
// save to temporary file
File dir = getTempDir();
if( dir != null )
{
FileOutputStream fos = null;
try
{
File f = File.createTempFile( "picture", ".stream", dir );
fos = new FileOutputStream( f );
picture.writeToStream( fos );
tempFile = f;
}
catch( IOException e )
{
Log.e( TAG, "failed to save picture", e );
}
finally
{
close( fos );
}
}
return tempFile;
}
Есть предложения о том, что мне не хватает?