-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android support for USB printers #38
Comments
I added a CoffeImage implementation to use Android Bitmap instead of BufferedImage Example code: val bm = BitmapFactory.decodeResource(resources, R.mipmap.myimage)
val imageWrapper = BitImageWrapper()
val algorithm = BitonalOrderedDither()
val escposImage = EscPosImage(BitmapCoffeeImage(bm), algorithm)
escpos.write(imageWrapper, escposImage)
//... Source: import android.graphics.Bitmap
import android.graphics.Color
import com.github.anastaciocintra.escpos.image.CoffeeImage
class BitmapCoffeeImage(val image:Bitmap): CoffeeImage {
override fun getHeight(): Int = image.height
override fun getWidth(): Int = image.width
override fun getSubimage(x: Int, y: Int, w: Int, h: Int): CoffeeImage = BitmapCoffeeImage( Bitmap.createBitmap(image,x,y,w,h))
override fun getRGB(x: Int, y: Int): Int {
val pixel = image.getPixel(x,y)
return (Color.alpha(pixel) shl 24 ) or (Color.red(pixel) shl 16) or (Color.green(pixel) shl 8) or (Color.blue(pixel) shl 0);
}
} |
1 similar comment
I added a CoffeImage implementation to use Android Bitmap instead of BufferedImage Example code: val bm = BitmapFactory.decodeResource(resources, R.mipmap.myimage)
val imageWrapper = BitImageWrapper()
val algorithm = BitonalOrderedDither()
val escposImage = EscPosImage(BitmapCoffeeImage(bm), algorithm)
escpos.write(imageWrapper, escposImage)
//... Source: import android.graphics.Bitmap
import android.graphics.Color
import com.github.anastaciocintra.escpos.image.CoffeeImage
class BitmapCoffeeImage(val image:Bitmap): CoffeeImage {
override fun getHeight(): Int = image.height
override fun getWidth(): Int = image.width
override fun getSubimage(x: Int, y: Int, w: Int, h: Int): CoffeeImage = BitmapCoffeeImage( Bitmap.createBitmap(image,x,y,w,h))
override fun getRGB(x: Int, y: Int): Int {
val pixel = image.getPixel(x,y)
return (Color.alpha(pixel) shl 24 ) or (Color.red(pixel) shl 16) or (Color.green(pixel) shl 8) or (Color.blue(pixel) shl 0);
}
} |
Good @plokko I don't know how to work with mix kotlin and java in one package. Or the best way to do this. But I know that some library for android are uncompatible with desktop. but before the package, feel invited to integrate the contributors team. So, in my hubble opinion, we need to pass on some phases:
If you agree, you can put the code on escpos-coffee-samples/miscellaneous/ Marco. |
I made this library work with Android USB printers by creating a custom OutputStream;
i also created some helper classes to ease the integration on Android.
The code is written in Kotlin and i also used Coroutines (not needed but they make the code a lot cleaner).
I'm not a package developer and i do understand this code may be better on a separate package but i'm not familiar with Java/Android package development so i'll leave the source here if anyone can help me release it.
Usage example:
Code:
The text was updated successfully, but these errors were encountered: