【问题标题】:iOS : How to convert an image gray scale to original by finger touch?iOS:如何通过手指触摸将图像灰度转换为原始灰度?
【发布时间】:2014-09-24 13:47:36
【问题描述】:

首先,我将图像原始转换为灰度并成功转换。但问题是,如何通过用户触摸该位置将灰度转换回原始图像。 我无法理解的是如何将**灰度转换为原始 **。

这是我的代码** 灰度原图 **

- (UIImage *)convertImageToGrayScale:(UIImage *)image
{
    CGRect imageRect = CGRectMake(0, 0, image.size.width, image.size.height);
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
    CGContextRef context = CGBitmapContextCreate(nil, image.size.width, image.size.height, 8, 0, colorSpace, kCGImageAlphaNone);
    CGContextDrawImage(context, imageRect, [image CGImage]);
    CGImageRef imageRef = CGBitmapContextCreateImage(context);
    UIImage *newImage = [UIImage imageWithCGImage:imageRef];
    CGColorSpaceRelease(colorSpace);
    CGContextRelease(context);
    CFRelease(imageRef);
    return newImage;
}

需要指导。提前致谢。

【问题讨论】:

    标签: ios image bitmap


    【解决方案1】:

    您无法将灰度图像转换回彩色图像,因为图像数据中不再有任何颜色信息。

    如果您的意思是您有一张要转换为灰度的彩色图像,然后当用户点击您时会显示彩色版本,那么您需要保留原始图像并以彩色显示该图像。

    【讨论】:

    • NO 我想要在灰度转换图像后。然后我想在屏幕上滑动手指。在谁的屏幕上手指滑动。该区域图像转换为他的原始颜色。我有一个示例快速启动应用程序。
    • @user3899098 听起来不是询问如何从灰度转换为 rgb,而是想知道如何在用户点击屏幕时将灰度图像换成彩色图像,这就是你问?
    【解决方案2】:

    我正在使用 98 x 98 像素的修复大小图像。我最终做的是在 Photoshop 中创建了一个空白的 98 x 98 png 并将其命名为 rgboverlay.png。然后我只是将我的灰度图像覆盖在空白图像的顶部,得到的图像是 RGB。这是代码。我最初获得了将一个图像叠加在另一个图像上的代码。

    originalimage = 你的灰度图像

    static UIImage* temp = nil;
    thumb = [UIImage imageNamed:@"rgboverlay.png"];
    CGSize size = CGSizeMake(98, 98);
    UIGraphicsBeginImageContext(size);
    CGPoint tempPoint = CGPointMake(0, 25 - temp.size.height / 2);
    [temp drawAtPoint:testPoint];
    CGPoint starredPoint = CGPointMake(1, 1);
    [originalimage drawAtPoint:starredPoint];
    // result is the new RGB image
    result = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    这最终对我有用。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-20
    • 2018-11-28
    • 1970-01-01
    • 2014-09-27
    相关资源
    最近更新 更多