问题
I'm using ePOS SDK from Epson which allows connecting to the printer (TM-T88V) via wifi. link for the sdk (http://pos.epson.com/mobilesdks/index.htm)
I'm loading an UIImage from a url using this code.
NSData* data = [[NSData alloc] initWithContentsOfUrl:_url];
UIImage* image = [UIImage imageWithData:data];
Then to Print the image (using ePOS) NOTE: I will skip the connecting part since it is not included to my question.
EposBuilder* builder = [EposBuilder alloc] initWithPrinterModel:@"TM-T88V" lang:EPOS_OC_MODEL_ANK];
EposPrint* printer = [[EposPrint alloc] init];
int retVal = EPOS_OC_SUCCESS;
unsigned long status = 0;
retVal = [builder addImage:image X:0 Y:0 Width:image.size.width Height:image.size.Height Color: EPOS_OC_COLOR_1];
retVal = [printer sendData:builder Timeout:10000 Status:&status];
Now my problem is that the printed result is alot smaller, see the size of the image is 271x368px. see image below for sample
Any ideas on how to make it print properly? Also i've found this Printing UIImage using AirPrint causes cut-off content which gave a link on scaling the image but it doesn't work. Any ideas? Thank you.
![](https://www.eimg.top/images/2020/03/22/cb1a11bddd1f4a19f30d50c15b0bca0e.jpg)
回答1:
I got the solution, don't mine of you already resolved it, The thing i did was, to save the Image in Documents folder through NSFileManager
and get the same from the documents folder and add a space to the image before adding, sorry for my english.. you need to implement your own code to save & retrive image through file manager.
NSData *dataFromUrl=[[NSData alloc] initWithContentsOfURL:url];
UIImage *image1 = [UIImage imageWithData:dataFromUrl];
if(image1)
{
[Filemanager saveReceiptLogoImage:image1];
}
//IN printer class,
UIImage *image1 = [Filemanager receiptLogo];
if(image1)
{
result = [builder addText:@" "];
UIImage *resizedImage = [image1 resizedImageWithContentMode:UIViewContentModeScaleAspectFit bounds:CGSizeMake(512, 350) interpolationQuality:kCGInterpolationHigh];
result = [builder addImage:resizedImage X:0 Y:0 Width:MIN(512, resizedImage.size.width) Height:resizedImage.size.height Color:EPOS_OC_COLOR_1];
}
来源:https://stackoverflow.com/questions/11578013/printing-uiimage-using-epos-sdk