2012-07-20 50 views
0

我使用Epson的ePOS SDK,它允許通過wifi連接到打印機(TM-T88V)。鏈接爲sdk(http://pos.epson.com/mobilesdks/index.htm使用ePOS SDK打印UIImage

我正在使用此代碼從URL加載UIImage。

NSData* data = [[NSData alloc] initWithContentsOfUrl:_url]; 
UIImage* image = [UIImage imageWithData:data]; 

然後打印圖像(使用EPOS)注:我將跳過連接的部分,因爲它不包括我的問題。

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]; 

現在我的問題是,打印的結果是小了很多,看到圖像的大小爲271x368px。請參閱下面的圖像樣本

有關如何使其正確打印的任何想法?我也發現這個Printing UIImage using AirPrint causes cut-off content它給了一個縮放圖像的鏈接,但它不起作用。有任何想法嗎?謝謝。

enter image description here

+0

任何人對此有一個解決方案嗎? – Iya 2016-03-04 07:50:16

+0

我建議你根據紙張尺寸 – 2017-12-22 11:15:38

回答

0

我得到了解決,不要的你我已經解決了,我做的事情是,在其中保存文件的影像通過NSFileManager文件夾,從文件夾得到相同的,並添加在添加圖片之前的空間,對不起我的英語..你需要實現自己的代碼,以通過文件管理器保存&回放圖像。

NSData *dataFromUrl=[[NSData alloc] initWithContentsOfURL:url]; 
    UIImage *image1 = [UIImage imageWithData:dataFromUrl]; 
    if(image1) 
    { 
     [Filemanager saveReceiptLogoImage:image1]; 
    } 

//打印機類,

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]; 
} 
+0

嘗試你的方法創建你的賬單圖像。但是圖像質量並不好。還可以使用UIViewContentModeScaleAspectToFill – jongbanaag 2013-05-20 12:46:20

+0

您可以向我顯示您的收據照片並使用resizedImageContentMode方法更新您的答案 – 2018-01-27 10:25:09