Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

processingでAndroid端末から画像印刷

More than 5 years have passed since last update.

Processingから直接プリントジョブを送るわけではないですが、
Android用のプリントアプリを介して印刷できたのでメモします。

プリンタがEPSONだったので、以下のような流れになりました。

  1. Android端末にEPSONの無料プリントアプリ「EPSON iPrint」を入れる。

  2. Processingから画像のシェアを要求。

  3. シェアのリストから「EPSON iPrint」を選んで印刷。

import android.view.MotionEvent;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.app.Activity;

Intent intent;

void setup () {
    size (displayWidth, displayHeight, JAVA2D);
    colorMode (RGB, 256);
    background (255);
    //Android端末のファイル保存環境を取得
    intent = new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()));
}

void draw () {
    fill (random (256), random (256), random (256));
    ellipse (random (width), random (height), 20, 20);
}

void mouseReleased () {
    //Android端末に画像を保存
    save_image ();
}

void save_image () {
    String img_name = Environment.getExternalStorageDirectory() + "/test_image.png";
    save (img_name);
    sendBroadcast (intent);
    //保存した後プリントアウト
    print_out (img_name);
}

void print_out (String img_path) {
    Intent shareIntent = new Intent (Intent.ACTION_SEND);
    shareIntent.setType ("image/png");
    shareIntent.putExtra (Intent.EXTRA_STREAM, Uri.fromFile (new File (img_path)));
    startActivity (shareIntent);
}

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away