我希望有人可以帮助
我有一个斑马ZQ520,我正在尝试从中打印测试标签 实际标签为832点* 400点(104mm * 50mm) 下面的脚本可以正常打印-尽管需要将整个图像旋转180以与标签上的标记(白色部分)对齐。 当“ UIImage * img1 = [self rotationImage:image byDegree: 90 ]”更改为“ [self rotationImage:image byDegree: 270 ]”时
整个东西损坏或变得奇怪..请帮助找到此代码中的错误 90 prints ok but needs to be rotated 180 degrees
此值为270 print is now squashed to the top and not rotated 如您所见,第二个图像现在也充满了黑色。.我不知道这些数据是从代码中来的。
希望有人有主意
(BOOL) sendImageToPrinter:(UIImage *)image {
UIImage *img1 = [self rotateImage:image byDegree:90];
if(!self.connectivityViewController.isBluetoothSelected) {
self.ipAddressText = [self.connectivityViewController.ipDnsTextField text];
self.portAsStringText = [self.connectivityViewController.portTextField text];
}
[self setZebraPrinter];
BOOL success = NO;
if(self.printer != nil) {
id<GraphicsUtil, NSObject> graphicsUtil = [self.printer getGraphicsUtil];
NSError *error = nil;
if (self.isStoreSelected) {
success = [graphicsUtil storeImage:self.pathOnPrinterText withImage:[img1 CGImage] withWidth:831 andWithHeight:400 error:&error];
} else {
success = [graphicsUtil printImage:[img1 CGImage] atX:0 atY:0 withWidth:831 withHeight:400 andIsInsideFormat:NO error:&error];
}
}
return success;
}
(UIImage )rotateImage:(UIImage )图像按度:(CGFloat)度 { UIView * rotatedViewBox = [[UIView分配] initWithFrame:CGRectMake(0,0,image.size.width,image.size.height)]; CGAffineTransform t = CGAffineTransformMakeRotation(DegreesToRadians(degrees)); rotationViewBox.transform = t; CGSize rotationSize = rotationViewBox.frame.size;
UIGraphicsBeginImageContext(rotatedSize); CGContextRef位图= UIGraphicsGetCurrentContext();
CGContextTranslateCTM(位图,旋转尺寸。宽度,旋转尺寸。高度);
CGContextRotateCTM(位图,DegreesToRadians(degrees));
CGContextScaleCTM(位图,1.0,-1.0); CGContextDrawImage(bitmap,CGRectMake(-image.size.width,-image.size.height,image.size.width,image.size.height),[image CGImage]);
UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 返回newImage;
}