infoxicator / react-native-star-prnt

React-Native bridge to communicate with Star Micronics Bluetooth/LAN Printers
MIT License
67 stars 65 forks source link

appendBitmap on Android does not resolve images from the Web #18

Closed dnlowman closed 5 years ago

dnlowman commented 5 years ago

The iOS implementation allows the resolution of images from the web however the android implementation does not, should we update the android implementation to support both resolving images from the web?

infoxicator commented 5 years ago

Hi @dnlowman not sure exactly what you refer to but I think one of the contributors fixed a problem with scaling on iOS, look at this commit. Maybe is also happening on android? is this to do with the appendBitmap command?

dnlowman commented 5 years ago

Hi @infoxicator, yes indeed it is in relation to the appendBitmap command, if you use a URI which is an image from the web the iOS implementation will actually resolve this and print the bitmap whereas the android implementation only searches the local filesystem so fails to print.

infoxicator commented 5 years ago

Hi @dnlowman, It looks like the iOS implementation creates an image regardless of the url (local or remote) NSURL *imageURL = [NSURL URLWithString:urlString]; NSData *imageData = [NSData dataWithContentsOfURL:imageURL]; UIImage *image = [UIImage imageWithData:imageData];

whereas the android implementation explicitly loads an image from the phone's memory:

Uri imageUri =  Uri.parse(uriString);
 Bitmap bitmap = MediaStore.Images.Media.getBitmap(contentResolver, imageUri);

The purpose of this command was always intended to be printing from the phone's memory not remote. One solution is to download your image and then pass it to appendBitmap function so it works on both platforms.

An alternative is maybe investigate if Java android allows you to pass a remote url to create a bitmap. The problem is to decide when is a remote image and when is a local one.