如何使用图像选择器将照片发送到我的惠普彩色打印机?
how to send a photo using image picker to my hp color printer?
我将一些图像发送到 firebase 存储,然后另一个获取图像并需要将其打印在相纸上。我可以用什么flutterAPI
我已经设法使用 methodchannel 调用本机 api,它似乎在重定向到打印服务。但它只转到打印服务,我必须点击打印并且不直接启动打印。
请添加您对如何直接启动打印的建议。
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;
});
}
我将一些图像发送到 firebase 存储,然后另一个获取图像并需要将其打印在相纸上。我可以用什么flutterAPI
我已经设法使用 methodchannel 调用本机 api,它似乎在重定向到打印服务。但它只转到打印服务,我必须点击打印并且不直接启动打印。
请添加您对如何直接启动打印的建议。
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;
});
}