简体   繁体   English

iOS:如何通过手指触摸将图像灰度转换为原始图像?

[英]iOS : How to convert an image gray scale to original by finger touch?

Firstly, I am converting an image original to gray scale and its successfully converted.首先,我将原始图像转换为灰度并成功转换。 But the problem is, how to convert gray scale back to original image by user touch on that place.但问题是,如何通过用户触摸那个地方将灰度转换回原始图像。 What I'm unable to understand is how to convert **Gray Scale to original **.我无法理解的是如何将**灰度转换为原始**。

Here is my code ** Original to gray scale **这是我的代码**原始到灰度**

- (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;
}

Guidance needed.需要指导。 Thanks in advance.提前致谢。

You can't convert a gray scale image back to color because you no longer have any color information in the image data.您无法将灰度图像转换回彩色,因为图像数据中不再有任何颜色信息。

If you mean you have a color image that you're converting to gray scale, and then when the user taps you show a color version, then instead you need to hang on to the original image and show that one in color.如果您的意思是将彩色图像转换为灰度,然后当用户点击时显示彩色版本,那么您需要保留原始图像并以彩色显示该图像。

I am using fixes size images which are 98 by 98 pixels.我正在使用 98 x 98 像素的修复尺寸图像。 What I ended up doing is created a blank 98 by 98 png in Photoshop and calling it rgboverlay.png.我最终做的是在 Photoshop 中创建了一个 98 x 98 的空白 png,并将其命名为 rgboverlay.png。 Then I just overlay my grayscale image on top of the blank one and the resulting image is RGB.然后我只是将我的灰度图像叠加在空白图像的顶部,结果图像是 RGB。 Here's the code.这是代码。 I originally got the code to overlay one image on another.我最初得到了将一个图像叠加在另一个图像上的代码。

originalimage = your grayscale image 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();

This ended up working for me.这最终对我有用。

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

相关问题 将图像转换为灰度 - Convert image to gray scale 对于IOS,如何使用vImage将ARGB图像转换为灰度图像 - For IOS, how to use vImage to convert an ARGB image to Gray image OpenGL iOS-无法在图像的手指触摸上应用模糊 - OpenGL iOS - apply blur on finger touch on image does not work 将颜色应用于灰度图像,保留alpha值(iOS / Quartz) - Applying color to gray scale image, preserving alpha values (iOS/Quartz) 如何使用加速框架(vImage)缩放灰度图像 - how to scale gray scale image using accelerate framework (vImage) 如何用透明像素对图像进行灰度处理,使所有像素都不透明? - How to gray scale an image with transparent pixels making all of them opaque? 如何在iOS / SWIFT / OBJ-C / CORDOVa上获取Finger iD(用于ID的手指)或唯一ID - How to get Finger iD (which finger is used for touch id) , or unique touch id on IOS/SWIFT/OBJ-C/CORDOVa 将图像转换为黑白图像,而无需使用iPhone中的设备灰度 - Convert image into black and white image without using Gray-scale of Device in iphone 图像在绘制后在每个触摸端上都会缩放-iOS - Image gets scale on every touch end after drawing on it - iOS 在Ionic App中通过手指(触摸)裁剪图像 - Crop image via finger(touch) in Ionic App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM