2017-01-27 7 views
1

OS XコードをiOS Objective-Cに書き込もうとしています。私はOS Xのために書かれたコードを持っていて、私はそのコードをiOSで使いたいと思っています。私はiOSのための以下のコードを書く方法がわかりません。 私はコードの下に変換されますが、私は私が私を助けてwarning.Pleaseの下に取得しています警告が一つだけ、このOS XコードをiOSに変換する

OS Xのコード

- (NSBitmapImageRep *) createImageRep:(NSSize)size 
{ 
    // Create an image rep that we can use as the backing store for the canvas. 
    // To keep things simple we'll use a 32-bit RGBA bitmap image. 
    int rowBytes = ((int)(ceil(size.width)) * 4 + 0x0000000F) & ~0x0000000F; // 16-byte aligned is good 
    NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil 
                 pixelsWide:size.width 
                 pixelsHigh:size.height 
                bitsPerSample:8 
                samplesPerPixel:4 
                  hasAlpha:YES 
                  isPlanar:NO 
                colorSpaceName:NSCalibratedRGBColorSpace 
                 bitmapFormat:NSAlphaNonpremultipliedBitmapFormat 
                 bytesPerRow:rowBytes 
                 bitsPerPixel:32]; 


    // Paint on a white background so the user has something to start with. 
    NSGraphicsContext* imageContext = [NSGraphicsContext graphicsContextWithBitmapImageRep:imageRep]; 

    // "Focus" our image rep so the NSImage will use it to draw into 
    [NSGraphicsContext saveGraphicsState]; 
    [NSGraphicsContext setCurrentContext:imageContext]; 

    [[NSColor whiteColor] set]; 
    [NSBezierPath fillRect: NSMakeRect(0, 0, size.width, size.height)]; 

    [NSGraphicsContext restoreGraphicsState]; 

    return imageRep; 
} 

に私を助けてくださいすることができますIOSコード

- (CGImageRef) createImageRep:(CGSize)size 
{ 


    int rowBytes = ((int)(ceil(size.width)) * 4 + 0x0000000F) & ~0x0000000F; // 16-byte aligned is good 

    CGImageRef maskCreate = CGImageMaskCreate(CGImageGetWidth((mImageRep)), 
               CGImageGetHeight((mImageRep)), 
               CGImageGetBitsPerComponent((mImageRep)), 
               CGImageGetBitsPerPixel((mImageRep)), 
               CGImageGetBytesPerRow((mImageRep)), 
               CGImageGetDataProvider((mImageRep)), NULL, false); 




    // Create an image rep that we can use as the backing store for the canvas. 
    // To keep things simple we'll use a 32-bit RGBA bitmap image. 



    // Paint on a white background so the user has something to start with. 
    CGImageRef masked = CGImageCreateWithMask(maskCreate, maskCreate); 

    CGImageRelease(maskCreate); 

    UIImage *maskedImage = [UIImage imageWithCGImage:masked]; 
    UIGraphicsEndImageContext(); 
    [[UIColor whiteColor] set]; 
    [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, size.width, size.height)]; 


    return maskedImage.CGImage; 
} 

を取得していますこれに。

Warning message

+1

まず自分を試してみてください。あなたが試したことでコードを投稿し、実際の問題を説明するのに問題がある場合。 – shallowThought

+0

私は試してみましたが、問題を抱えている人は、IOSのNSGraphicsContext *コードで以下のコードを書く方法を教えてください。* imageContext = [NSGraphicsContext graphicsContextWithBitmapImageRep:imageRep]; – Uttam

+0

https://s23.postimg.org/3ma5br66z/Screen_Shot_2017_01_27_at_2_24_00_PM.png – Uttam

答えて

1

エラーがあなたのメソッドの戻り値の型が、以前の宣言と矛盾すると述べています。

MyCLass.mであなたの実装では、次のとおりです。

- (CGImageRef *) createImageRep:(CGSize)size ... 

は、おそらくあなたが誤って *を追加しました:

- (CGImageRef) createImageRep:(CGSize)size 

あなたは別の戻り値の型と、以前に宣言を持っています。

確認し、この宣言のMyCLass.hヘッダファイル:

- (CGImageRef *)createImageRep:(CGSize)size; 

と削除*

- (CGImageRef)createImageRep:(CGSize)size; 
関連する問題