简体   繁体   English

将 OS X 代码转换为 iOS

[英]Convert OS X code to iOS

I'm trying to write OS X code to iOS Objective-C.我正在尝试将 OS X 代码写入 iOS Objective-C。 I have code written for OS X and I want to use that code in iOS.我有为 OS X 编写的代码,我想在 iOS 中使用该代码。 I am not sure how to write the below code for iOS.我不确定如何为 iOS 编写以下代码。 I converted below code but I am getting warnings can only one please help me on this我转换了下面的代码,但我收到警告只能一个请帮助我

OS X code 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 code 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;
}

I am getting below warning.Please help me on this.我的警告低于警告。请帮助我。

警告信息

The error states that the return type of your method conflicts with a previous declaration.该错误指出您的方法的返回类型与先前的声明冲突。

Your implementation in MyCLass.m is:您在MyCLass.m中的实现是:

- (CGImageRef) createImageRep:(CGSize)size

You do have previously declaration with a different return type:您之前确实有使用不同返回类型的声明:

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

Probably you have added the * accidentally.可能您不小心添加了*

Check the MyCLass.h header file for this declaration:检查MyCLass.h头文件以获取此声明:

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

and remove the * :并删除*

- (CGImageRef)createImageRep:(CGSize)size;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM