0
qr을 생성하여 PNG로 내보내려고하지만이를 수행 할 때마다 흐리게 처리 된 이미지로 내 보냅니다. 내가 모호하지 않게하기 위해 내가 무엇을 할 수 있는지 확신 할 수 없다.내 보낸 PNG가 흐립니다.
은 2 경우에 발생합니다
- 을 미리보기 창
- 내가 파일 여기
내가 사용하고있는 코드가를 내보낼 때. 제가 언어에 익숙하지 않고 물건을 찾아 내려고 노력하면서 어떤 도움이나 조언을 주시면 대단히 감사하겠습니다. 여기
내 코드를 제공 :- (NSImage *)scaleImageTo:(NSImage *)inputImage size:(NSSize)newSize
{
NSImage *cropped = [[NSImage alloc] initWithSize:NSMakeSize(newSize.width, newSize.height)];
[cropped lockFocus];
[inputImage drawInRect:NSMakeRect(0,0,cropped.size.width,cropped.size.height)
fromRect:NSMakeRect(0,0,inputImage.size.width,inputImage.size.height)
operation:NSCompositeCopy
fraction:1.0];
[cropped unlockFocus];
NSRect rect = NSMakeRect(0, 0, cropped.size.width, cropped.size.height);
CIImage* ciImage1 = [[CIImage alloc] initWithData:[cropped TIFFRepresentation]];
[[NSGraphicsContext currentContext] setShouldAntialias: NO];
NSImage *buffer2 = [[NSImage alloc] initWithSize:NSMakeSize([cropped size].width , [cropped size].height)];
[buffer2 lockFocus];
CIFilter* filter2 = [CIFilter filterWithName:@"CIMaskToAlpha"];
[filter2 setValue:ciImage1 forKey:@"inputImage"];
CIImage* output2 = [filter2 valueForKey:@"outputImage"];
[output2 drawAtPoint:NSZeroPoint fromRect:rect operation:NSCompositeSourceOver fraction:1.0];
//background
[[_backgroundColorSelector color] set];
NSRectFillUsingOperation(rect, NSCompositeSourceAtop);
//foreground
[[_foregroundColorSelector color] set];
NSRectFillUsingOperation(rect, NSCompositeDestinationAtop);
[buffer2 unlockFocus];
return buffer2;
}
- (void)writeImageAt:(NSImage *)img path:(NSString *)strPath
{
//create a NSBitmapImageRep
NSBitmapImageRep *bmpImageRep = [[NSBitmapImageRep alloc]initWithData:[img TIFFRepresentation]];
//add the NSBitmapImage to the representation list of the target
[img addRepresentation:bmpImageRep];
//get the data from the representation
NSData *data = [bmpImageRep representationUsingType: NSPNGFileType
properties: nil];
[data writeToFile:strPath atomically:YES];
}
- (void)savePNGAt:(NSImage *)img path:(NSString *)strPath
{
NSString * qrWidth = [_qrWidth stringValue];
NSString * qrHeight = [_qrHeight stringValue];
if (qrHeight != nil && ![qrWidth isEqualToString:@""] && qrWidth != nil && ![qrHeight isEqualToString:@""]) {
NSSize newSize = NSMakeSize([qrWidth floatValue], [qrHeight floatValue]);
img = [self scaleImageTo:img size:newSize];
[self writeImageAt:img path:strPath];
}
else
{
img = [self changeImageColor:img];
[self writeImageAt:img path:strPath];
}
}