【问题标题】:how to send a photo using image picker to my hp color printer?如何使用图像选择器将照片发送到我的 hp 彩色打印机?
【发布时间】:2022-01-15 18:11:51
【问题描述】:

我将一些图像发送到 Firebase 存储,然后另一个获取图像并需要将其打印在相纸上。我可以使用什么 Flutter API。

我已经设法使用方法通道调用本机 api,它似乎在重定向到打印服务。但它只进入打印服务,我必须点击打印并且不直接启动打印。

请添加您对如何直接启动打印的建议。

【问题讨论】:

标签: android flutter printing imagepicker


【解决方案1】:
package com.example.print1
import android.content.Context
import android.content.ContextWrapper
import android.content.Intent
import android.content.IntentFilter
import android.os.BatteryManager
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import android.R
import androidx.print.PrintHelper
import android.graphics.BitmapFactory
import android.R.drawable
class MainActivity : FlutterActivity() {
    private val CHANNEL = "samples.flutter.dev/battery"
    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler {
            // Note: this method is invoked on the main thread.
                call, result ->
            if (call.method == "Printphoto") {
                doPhotoPrint()

            } else {
                result.notImplemented()
            }
        }
    }


    private fun doPhotoPrint() {
        println("heloo the yout");
        activity.also { context ->
            PrintHelper(context).apply {
                scaleMode = PrintHelper.SCALE_MODE_FIT
            }.also { printHelper ->
                val bitmap = BitmapFactory.decodeResource(resources, R.drawable.alert_dark_frame)
                printHelper.printBitmap("droids.jpg - test print", bitmap)
            }
        }

    }
}


static const platform = const MethodChannel('samples.flutter.dev/battery');
      String _printstatus =       'printing photo';
      Future<void> Printphotocall() async {
        String batteryLevel;
        try {
          final int result = await platform.invokeMethod('doPhotoPrint');
          _printstatus = 'Battery level at $result % .';
        } on PlatformException catch (e) {
          _printstatus = "Failed to print: '${e.message}'.";
        }
        setState(() {
          _printstatus = batteryLevel;
        });
      }

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center。
猜你喜欢
  • 1970-01-01
  • 2023-03-31
  • 1970-01-01
  • 2011-01-20
  • 2021-10-04
  • 1970-01-01
  • 2018-12-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多