Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ios将文本与图像合并不';不能使用非wetsern字符_Ios_Xcode_Localization_Uiimageview_Utf 16 - Fatal编程技术网

ios将文本与图像合并不';不能使用非wetsern字符

ios将文本与图像合并不';不能使用非wetsern字符,ios,xcode,localization,uiimageview,utf-16,Ios,Xcode,Localization,Uiimageview,Utf 16,我正在尝试开发本地化的帮助文件。它适用于西方语言,但不显示非西方字符(仅输出图像文件)。如果文本以utf-8或utf-16编码,也会发生同样的情况 我不喜欢发布所有这些代码,但我就是找不到问题所在。 非常感谢任何帮助 - (IBAction)segmentedControlChanged:(UISegmentedControl *)sender { UIImage *helpImage; NSArray *helpText; if (sender.selected

我正在尝试开发本地化的帮助文件。它适用于西方语言,但不显示非西方字符(仅输出图像文件)。如果文本以utf-8或utf-16编码,也会发生同样的情况 我不喜欢发布所有这些代码,但我就是找不到问题所在。 非常感谢任何帮助

    - (IBAction)segmentedControlChanged:(UISegmentedControl *)sender {
    UIImage *helpImage;
    NSArray *helpText;
    if (sender.selectedSegmentIndex == 1) {
        helpImage = [UIImage imageNamed:@"HelpImage.png"];
        helpText = [NSArray arrayWithObjects:
                    [NSDictionary dictionaryWithObjectsAndKeys:
                     NSLocalizedString(@"Tab1 - sample text", nil), kHelpTextKeyString,
                     @"Arial", kHelpTextKeyFontName,
                     //@"Helvetica-Bold", kHelpTextKeyFontName,
                     [NSNumber numberWithInt:20], kHelpTextKeyFontSize,
                     [[UIColor blackColor] CGColor], kHelpTextKeyColor,
                     CGRectCreateDictionaryRepresentation(CGRectMake(30.0, 55.0, 200.0, 28.0)), kHelpTextKeyRect,
                     nil],
                    // CGRectCreateDictionaryRepresentation(CGRectMake(38.0, 55.0, 200.0, 28.0)), kHelpTextKeyRect,
                    //CGRectCreateDictionaryRepresentation(CGRectMake(30.0, 55.0, 200.0, 28.0)), kHelpTextKeyRect,

                    [NSDictionary dictionaryWithObjectsAndKeys:
                     [NSArray arrayWithObjects:
                      NSLocalizedString(@"sample text ", nil),
                      NSLocalizedString(@" ", nil),
                      NSLocalizedString(@"more sample text", nil),
                      nil], kHelpTextKeyString,
                     @"Helvetica-Light", kHelpTextKeyFontName,
                     [NSNumber numberWithInt:10], kHelpTextKeyFontSize,
                     [[UIColor blackColor] CGColor], kHelpTextKeyColor,
                     CGRectCreateDictionaryRepresentation(CGRectMake(10.0, 80.0, 200.0, 28.0)), kHelpTextKeyRect,
                     nil],
                    nil];
    }

    // display actual image
    [self displaySelectedHelpImage:helpImage withTextArray:helpText];
}


/

    / merge selected help image to text
    - (void)displaySelectedHelpImage:(UIImage *)orgImage withTextArray:(NSArray *)textArr {
        CGImageRef cgImage = [orgImage CGImage];
        int pixelsWide              = CGImageGetWidth(cgImage);
        int pixelsHigh              = CGImageGetHeight(cgImage);
        int bitsPerComponent        = CGImageGetBitsPerComponent(cgImage);//8; // fixed
        int bitsPerPixel            = CGImageGetBitsPerPixel(cgImage);//bitsPerComponent * numberOfCompnent;
        int bytesPerRow             = CGImageGetBytesPerRow(cgImage);//(pixelsWide * bitsPerPixel) // 8; // bytes
        int byteCount               = (bytesPerRow * pixelsHigh);
        CGColorSpaceRef colorSpace  = CGImageGetColorSpace(cgImage);//CGColorSpaceCreateDeviceRGB();

    // Allocate data
    NSMutableData *data = [NSMutableData dataWithLength:byteCount];
    // Create a bitmap context
    CGContextRef context = CGBitmapContextCreate([data mutableBytes], pixelsWide, pixelsHigh, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); //kCGImageAlphaPremultipliedLast);//kCGImageAlphaNoneSkipLast); //kCGImageAlphaOnly);
    // Set the blend mode to copy to avoid any alteration of the source data or to invert to invert image
    CGContextSetBlendMode(context, kCGBlendModeCopy);
    // Set alpha
    CGContextSetAlpha(context, 1.0);
    // Color image
    //CGContextSetRGBFillColor(context, 1 ,1, 1, 1.0);
    //CGContextFillRect(context, CGRectMake(0.0, 0.0, pixelsWide, pixelsHigh));
    // Draw the image to extract the alpha channel
    CGContextDrawImage(context, CGRectMake(0.0, 0.0, pixelsWide, pixelsHigh), cgImage);

    // add text to image
    // Changes the origin of the user coordinate system in a context
    //CGContextTranslateCTM (context, pixelsWide, pixelsHigh);
    // Rotate context upright
    //CGContextRotateCTM (context, -180. *  M_PI/180);
    for (NSDictionary *dic in textArr) {

        CGContextSelectFont (context,
                             //todo
                             [[dic objectForKey:kHelpTextKeyFontName] UTF8String],
                             [[dic objectForKey:kHelpTextKeyFontSize] intValue],
                             kCGEncodingMacRoman);
        CGContextSetCharacterSpacing (context, 2);
        CGContextSetTextDrawingMode (context, kCGTextFillStroke);

        CGColorRef color = (CGColorRef)[dic objectForKey:kHelpTextKeyColor];
        CGRect rect;
        CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[dic objectForKey:kHelpTextKeyRect], &rect);

        CGContextSetFillColorWithColor(context, color);
        CGContextSetStrokeColorWithColor(context, color); 

        if ([[dic objectForKey:kHelpTextKeyString] isKindOfClass:[NSArray class]]) {
            for (NSString *str in [dic objectForKey:kHelpTextKeyString]) {
                CGContextShowTextAtPoint(context,
                                         rect.origin.x,
                                         pixelsHigh - rect.origin.y,
                                         [str cStringUsingEncoding:[NSString defaultCStringEncoding]],
                                         [str length]);
                rect.origin.y += [[dic objectForKey:kHelpTextKeyFontSize] intValue];
            }
        } else {
            CGContextShowTextAtPoint(context,
                                     rect.origin.x,
                                     pixelsHigh - rect.origin.y,
                                     [[dic objectForKey:kHelpTextKeyString] cStringUsingEncoding:[NSString defaultCStringEncoding]],
                                     [[dic objectForKey:kHelpTextKeyString] length]);
        }
    }

    // Now the alpha channel has been copied into our NSData object above, so discard the context and lets make an image mask.
    CGContextRelease(context);
    // Create a data provider for our data object (NSMutableData is tollfree bridged to CFMutableDataRef, which is compatible with CFDataRef)
    CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData((CFMutableDataRef)data);
    // Create our new mask image with the same size as the original image
    //CGImageRef maskingImage = CGImageMaskCreate(pixelsWide, pixelsHigh, bitsPerComponent, bitsPerPixel, bytesPerRow, dataProvider, NULL, YES);

    CGImageRef finalImage = CGImageCreate(pixelsWide,
                                          pixelsHigh,
                                          bitsPerComponent,
                                          bitsPerPixel,
                                          bytesPerRow,
                                          colorSpace,
                                          kCGBitmapByteOrderDefault,
                                          dataProvider,
                                          NULL,
                                          YES,
                                          kCGRenderingIntentDefault);

    // And release the provider.
    CGDataProviderRelease(dataProvider);

    UIImage *theImage = [UIImage imageWithCGImage:finalImage];

    // remove old scroll view
    if (scrollView) {
        [scrollView removeFromSuperview];
    }

    // construct new scroll view and size according to image
    UIScrollView *tempScrollView = [[UIScrollView alloc] initWithFrame:containerView.bounds];
    tempScrollView.contentSize = theImage.size; 
    scrollView = tempScrollView;

    // construct an image view (sized at zero) and assign the help image to it
    UIImageView *tempImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, theImage.size.width, 0.0)];
    [tempImageView setImage:theImage];

    // push image view to scrolle view and scroll view to container view
    [tempScrollView addSubview:tempImageView];
    [containerView addSubview:tempScrollView];

    // animate
    [UIView beginAnimations:@"ResizeImageView" context:NULL];
    [UIView setAnimationDuration:1.0];

    // recover actual image size through animation
    [tempImageView setFrame:CGRectMake(0.0, 0.0, theImage.size.width, theImage.size.height)];

    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve: UIViewAnimationCurveEaseOut];

    [UIView commitAnimations];- (IBAction)segmentedControlChanged:(UISegmentedControl *)sender {
    UIImage *helpImage;
    NSArray *helpText;
    if (sender.selectedSegmentIndex == 1) {
        helpImage = [UIImage imageNamed:@"HelpImage.png"];
        helpText = [NSArray arrayWithObjects:
                    [NSDictionary dictionaryWithObjectsAndKeys:
                     NSLocalizedString(@"Tab1 - sample text", nil), kHelpTextKeyString,
                     @"Arial", kHelpTextKeyFontName,
                     //@"Helvetica-Bold", kHelpTextKeyFontName,
                     [NSNumber numberWithInt:20], kHelpTextKeyFontSize,
                     [[UIColor blackColor] CGColor], kHelpTextKeyColor,
                     CGRectCreateDictionaryRepresentation(CGRectMake(30.0, 55.0, 200.0, 28.0)), kHelpTextKeyRect,
                     nil],
                    // CGRectCreateDictionaryRepresentation(CGRectMake(38.0, 55.0, 200.0, 28.0)), kHelpTextKeyRect,
                    //CGRectCreateDictionaryRepresentation(CGRectMake(30.0, 55.0, 200.0, 28.0)), kHelpTextKeyRect,

                    [NSDictionary dictionaryWithObjectsAndKeys:
                     [NSArray arrayWithObjects:
                      NSLocalizedString(@"sample text ", nil),
                      NSLocalizedString(@" ", nil),
                      NSLocalizedString(@"more sample text", nil),
                      nil], kHelpTextKeyString,
                     @"Helvetica-Light", kHelpTextKeyFontName,
                     [NSNumber numberWithInt:10], kHelpTextKeyFontSize,
                     [[UIColor blackColor] CGColor], kHelpTextKeyColor,
                     CGRectCreateDictionaryRepresentation(CGRectMake(10.0, 80.0, 200.0, 28.0)), kHelpTextKeyRect,
                     nil],
                    nil];
    }

    // display actual image
    [self displaySelectedHelpImage:helpImage withTextArray:helpText];
}


// merge selected help image to text
- (void)displaySelectedHelpImage:(UIImage *)orgImage withTextArray:(NSArray *)textArr {
    CGImageRef cgImage = [orgImage CGImage];
    int pixelsWide              = CGImageGetWidth(cgImage);
    int pixelsHigh              = CGImageGetHeight(cgImage);
    int bitsPerComponent        = CGImageGetBitsPerComponent(cgImage);//8; // fixed
    int bitsPerPixel            = CGImageGetBitsPerPixel(cgImage);//bitsPerComponent * numberOfCompnent;
    int bytesPerRow             = CGImageGetBytesPerRow(cgImage);//(pixelsWide * bitsPerPixel) // 8; // bytes
    int byteCount               = (bytesPerRow * pixelsHigh);
    CGColorSpaceRef colorSpace  = CGImageGetColorSpace(cgImage);//CGColorSpaceCreateDeviceRGB();

    // Allocate data
    NSMutableData *data = [NSMutableData dataWithLength:byteCount];
    // Create a bitmap context
    CGContextRef context = CGBitmapContextCreate([data mutableBytes], pixelsWide, pixelsHigh, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast); //kCGImageAlphaPremultipliedLast);//kCGImageAlphaNoneSkipLast); //kCGImageAlphaOnly);
    // Set the blend mode to copy to avoid any alteration of the source data or to invert to invert image
    CGContextSetBlendMode(context, kCGBlendModeCopy);
    // Set alpha
    CGContextSetAlpha(context, 1.0);
    // Color image
    //CGContextSetRGBFillColor(context, 1 ,1, 1, 1.0);
    //CGContextFillRect(context, CGRectMake(0.0, 0.0, pixelsWide, pixelsHigh));
    // Draw the image to extract the alpha channel
    CGContextDrawImage(context, CGRectMake(0.0, 0.0, pixelsWide, pixelsHigh), cgImage);

    // add text to image
    // Changes the origin of the user coordinate system in a context
    //CGContextTranslateCTM (context, pixelsWide, pixelsHigh);
    // Rotate context upright
    //CGContextRotateCTM (context, -180. *  M_PI/180);
    for (NSDictionary *dic in textArr) {

        CGContextSelectFont (context,
                             //todo
                             [[dic objectForKey:kHelpTextKeyFontName] UTF8String],
                             [[dic objectForKey:kHelpTextKeyFontSize] intValue],
                             kCGEncodingMacRoman);
        CGContextSetCharacterSpacing (context, 2);
        CGContextSetTextDrawingMode (context, kCGTextFillStroke);

        CGColorRef color = (CGColorRef)[dic objectForKey:kHelpTextKeyColor];
        CGRect rect;
        CGRectMakeWithDictionaryRepresentation((CFDictionaryRef)[dic objectForKey:kHelpTextKeyRect], &rect);

        CGContextSetFillColorWithColor(context, color);
        CGContextSetStrokeColorWithColor(context, color); 

        if ([[dic objectForKey:kHelpTextKeyString] isKindOfClass:[NSArray class]]) {
            for (NSString *str in [dic objectForKey:kHelpTextKeyString]) {
                CGContextShowTextAtPoint(context,
                                         rect.origin.x,
                                         pixelsHigh - rect.origin.y,
                                         [str cStringUsingEncoding:[NSString defaultCStringEncoding]],
                                         [str length]);
                rect.origin.y += [[dic objectForKey:kHelpTextKeyFontSize] intValue];
            }
        } else {
            CGContextShowTextAtPoint(context,
                                     rect.origin.x,
                                     pixelsHigh - rect.origin.y,
                                     [[dic objectForKey:kHelpTextKeyString] cStringUsingEncoding:[NSString defaultCStringEncoding]],
                                     [[dic objectForKey:kHelpTextKeyString] length]);
        }
    }

    // Now the alpha channel has been copied into our NSData object above, so discard the context and lets make an image mask.
    CGContextRelease(context);
    // Create a data provider for our data object (NSMutableData is tollfree bridged to CFMutableDataRef, which is compatible with CFDataRef)
    CGDataProviderRef dataProvider = CGDataProviderCreateWithCFData((CFMutableDataRef)data);
    // Create our new mask image with the same size as the original image
    //CGImageRef maskingImage = CGImageMaskCreate(pixelsWide, pixelsHigh, bitsPerComponent, bitsPerPixel, bytesPerRow, dataProvider, NULL, YES);

    CGImageRef finalImage = CGImageCreate(pixelsWide,
                                          pixelsHigh,
                                          bitsPerComponent,
                                          bitsPerPixel,
                                          bytesPerRow,
                                          colorSpace,
                                          kCGBitmapByteOrderDefault,
                                          dataProvider,
                                          NULL,
                                          YES,
                                          kCGRenderingIntentDefault);

    // And release the provider.
    CGDataProviderRelease(dataProvider);

    UIImage *theImage = [UIImage imageWithCGImage:finalImage];

    // remove old scroll view
    if (scrollView) {
        [scrollView removeFromSuperview];
    }

    // construct new scroll view and size according to image
    UIScrollView *tempScrollView = [[UIScrollView alloc] initWithFrame:containerView.bounds];
    tempScrollView.contentSize = theImage.size; 
    scrollView = tempScrollView;

    // construct an image view (sized at zero) and assign the help image to it
    UIImageView *tempImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, theImage.size.width, 0.0)];
    [tempImageView setImage:theImage];

    // push image view to scrolle view and scroll view to container view
    [tempScrollView addSubview:tempImageView];
    [containerView addSubview:tempScrollView];

    // animate
    [UIView beginAnimations:@"ResizeImageView" context:NULL];
    [UIView setAnimationDuration:1.0];

    // recover actual image size through animation
    [tempImageView setFrame:CGRectMake(0.0, 0.0, theImage.size.width, theImage.size.height)];

    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve: UIViewAnimationCurveEaseOut];

    [UIView commitAnimations];

您正在使用
CGContextShowTextAtPoint
绘制文本,它对非ASCII文本的支持较差

类似问题:


使用更高级别的API来绘制文本,如
UIKit/UIStringDrawing.h
中的方法,如
-[NSString drawAtPoint:withFont:][/code>

您正在使用
CGContextShowTextAtPoint
绘制文本,该方法对非ASCII文本的支持较差

类似问题:


使用更高级的API来绘制文本,比如
UIKit/UIStringDrawing.h
中的方法,比如
-[NSString drawAtPoint:withFont:][/code>

啊哈,这真的很有趣。我会试一试,让你知道我进展如何,非常感谢。尽管如此,继续努力,但肯定会很好。谢谢对于面对这个问题的人来说,它是通过使用CaleTeXBoundation类来解决的。啊哈,这真的很有趣。我会试一试,让你知道我进展如何,非常感谢。尽管如此,继续努力,但肯定会很好。谢谢对于任何面临这个问题的人来说,它是通过使用CaleTeXBoundation类来解决的。