Coder Social home page Coder Social logo

App craches, the package bluetooth_print can't print images on ios, it's working in android but doesn't work in iOS about bluetooth_print HOT 6 OPEN

HamzaMihfad avatar HamzaMihfad commented on August 17, 2024 1
App craches, the package bluetooth_print can't print images on ios, it's working in android but doesn't work in iOS

from bluetooth_print.

Comments (6)

aargjjendi avatar aargjjendi commented on August 17, 2024

I'm having the same issue, did you find any solution ?

from bluetooth_print.

Scuttman avatar Scuttman commented on August 17, 2024

I was having the same issue in Android. I noticed that the example app on pub.dev had the line to show the image commented out!

However, I discovered that the error is because the image size has not been set. For the image, you have to set an int value under width:200 for example. This then works. Have not tested in IOS but not setting the width caused a compile error. Once the width was set, error was removed and image printed.

printList.add(LineText(type: LineText.TYPE_IMAGE, width:200, content: base64Image, align: LineText.ALIGN_CENTER, linefeed: 1));

from bluetooth_print.

Niagawan-mave avatar Niagawan-mave commented on August 17, 2024

I am also facing the same issues, did anyone have the solution ?
I have set the width and height to 100. it work great in android, but in IOS it cannot print image, it show the error above

from bluetooth_print.

Niagawan-mave avatar Niagawan-mave commented on August 17, 2024

I have solved the problem but adding resizing code in IOS
You can go to ios/Classes/BluetoothPrintPlugin.m
Then look for function mapToEscCommand, within it have a part is else if([@"image" isEqualToString:type]){
replace the code below will solved the ios printer image cannot print problem

else if([@"image" isEqualToString:type]){
NSData *decodeData = [[NSData alloc] initWithBase64EncodedString:content options:0];
UIImage *image = [UIImage imageWithData:decodeData];
// Define the maximum width
CGFloat maxWidth = 100.0; // Adjust the maximum width as needed

        // Calculate the target size while maintaining the original aspect ratio
        CGSize originalSize = image.size;
        CGFloat scaleFactor = maxWidth / originalSize.width;
        CGSize targetSize = CGSizeMake(originalSize.width * scaleFactor, originalSize.height * scaleFactor);

        // Create a renderer with the calculated target size
        UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:targetSize];

        // Render the image and get a new data representation
        NSData *renderedImageData = [renderer JPEGDataWithCompressionQuality:1 actions:^(UIGraphicsImageRendererContext * _Nonnull context) {
            [image drawInRect:CGRectMake(0, 0, targetSize.width, targetSize.height)];
        }];
        UIImage *resizedImage = [UIImage imageWithData:renderedImageData];
        [command addOriginrastBitImage:resizedImage];
    }

from bluetooth_print.

HamzaMihfad avatar HamzaMihfad commented on August 17, 2024

@Niagawan-mave thanks a lot, finally it's working on ios now

did you create a new package on pub.dev? or just forked it to your github account?

from bluetooth_print.

Niagawan-mave avatar Niagawan-mave commented on August 17, 2024

@HamzaMihfad I just forked to my github account

from bluetooth_print.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.