相关疑难解决方法(0)

获取UIImage的Pixel颜色

如何获取UIImage中特定像素的RGB值?

iphone rgb pixel uiimage

58
推荐指数
8
解决办法
6万
查看次数

检索UIImage的像素alpha值

我目前正在尝试获取UIImageView中像素的alpha值.我从[UIImageView image]中获取了CGImage,并从中创建了一个RGBA字节数组.Alpha是预乘的.

CGImageRef image = uiImage.CGImage;
NSUInteger width = CGImageGetWidth(image);
NSUInteger height = CGImageGetHeight(image);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
rawData = malloc(height * width * 4);
bytesPerPixel = 4;
bytesPerRow = bytesPerPixel * width;

NSUInteger bitsPerComponent = 8;
CGContextRef context = CGBitmapContextCreate(
    rawData, width, height, bitsPerComponent, bytesPerRow, colorSpace,
    kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big
);
CGColorSpaceRelease(colorSpace);

CGContextDrawImage(context, CGRectMake(0, 0, width, height), image);
CGContextRelease(context);
Run Code Online (Sandbox Code Playgroud)

然后,我使用UIImageView中的坐标计算给定alpha通道的数组索引.

int byteIndex = (bytesPerRow * uiViewPoint.y) + uiViewPoint.x * bytesPerPixel;
unsigned char alpha = rawData[byteIndex + 3];
Run Code Online (Sandbox Code Playgroud)

但是我没有得到我期望的价值.对于图像的完全黑色透明区域,我得到alpha通道的非零值.我是否需要翻译UIKit和Core Graphics之间的坐标 - …

iphone core-graphics quartz-graphics uikit

35
推荐指数
2
解决办法
2万
查看次数

iOS 6 MFMailComposeViewController:仅支持RGBA或White颜色空间,此方法是黑客攻击

真的,真奇怪的错误

我有一个在iOS5/.1中工作正常的应用程序,现在我有一些iOS6的转换问题,但这个令人困惑.

我有一些代码启动邮件编写器,并且自iOS 6以来它会导致此错误崩溃:

*断言失败 - [UICGColor encodeWithCoder:],/ SourceCache/UIKit/UIKit-2372/UIColor.m:1191 2012-09-26 02:14:38.044 MyCQs Medical [2126:1b03]*由于未捕获的异常而终止应用程序' NSInternalInconsistencyException',原因:'只支持RGBA或White颜色空间,这种方法是黑客攻击.

有什么建议?通过试验和错误注释各行,它似乎是导致错误的alloc/init行,但是当所有行都被取消注释时,所有的NSLog都被执行,包括"present",表示应调用的所有内容,一直都是.在邮件组件显示在屏幕上之前应用程序崩溃,我真的很感激这里有任何建议

            if (indexPath.row == 3) {
               if([MFMailComposeViewController canSendMail]){
                   mailComposer = [[MFMailComposeViewController alloc]init];
                   NSLog(@"Alloc, init");
                   mailComposer.mailComposeDelegate = self;
                   NSLog(@"Set delegate");
                   NSArray *toArray = [[NSArray alloc]initWithObjects:@"john@doe.com", nil];
                   NSLog(@"To array");
                   [mailComposer setToRecipients:toArray];
                   NSLog(@"To recipients");
                   [mailComposer setSubject:@"Message from a MyCQs user!"];
                   NSLog(@"Subject");
                   NSLog(@"About to present mail composer");
                   [[mailComposer navigationBar] setTintColor:[UIColor blackColor]];
                   [self presentModalViewController:mailComposer animated:YES];
                   NSLog(@"Present");
             }
    }
Run Code Online (Sandbox Code Playgroud)

iphone xcode objective-c ios ios6

27
推荐指数
3
解决办法
7106
查看次数

如何在图像上实现alpha渐变?

我想在图像上实现alpha渐变.从图像顶部的0.5 alfa到底部的0.0.欢迎任何建议,教程和链接.

iphone gradient alpha quartz-2d ios

15
推荐指数
2
解决办法
1万
查看次数

OCR:图像到文字?

在标记为复制或重复问题之前,请先阅读整个问题.

我能够在现有的情况下做到如下:

  1. 获取图像并裁剪OCR所需的部分.
  2. 使用tesseract和处理图像leptonica.
  3. 当应用文档以块的形式裁剪时,即每个图像1个字符,它提供96%的准确度.
  4. 如果我不这样做,文档背景为白色,文本为黑色,则精度几乎相同.

例如,如果输入是这张照片:

照片开始

在此输入图像描述

照片结束

我想要的是能够为这张照片获得相同的准确度在此输入图像描述
没有生成块.

我用来初始化从图像中提取和提取文本的代码如下:

对于tesseract的初始化

在.h文件中

tesseract::TessBaseAPI *tesseract;
uint32_t *pixels;
Run Code Online (Sandbox Code Playgroud)

在.m文件中

tesseract = new tesseract::TessBaseAPI();
tesseract->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding], "eng");
tesseract->SetPageSegMode(tesseract::PSM_SINGLE_LINE);
tesseract->SetVariable("tessedit_char_whitelist", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
tesseract->SetVariable("language_model_penalty_non_freq_dict_word", "1");
tesseract->SetVariable("language_model_penalty_non_dict_word ", "1");
tesseract->SetVariable("tessedit_flip_0O", "1");
tesseract->SetVariable("tessedit_single_match", "0");
tesseract->SetVariable("textord_noise_normratio", "5");
tesseract->SetVariable("matcher_avg_noise_size", "22");
tesseract->SetVariable("image_default_resolution", "450");
tesseract->SetVariable("editor_image_text_color", "40");
tesseract->SetVariable("textord_projection_scale", "0.25");
tesseract->SetVariable("tessedit_minimal_rejection", "1");
tesseract->SetVariable("tessedit_zero_kelvin_rejection", "1");
Run Code Online (Sandbox Code Playgroud)

从图像中获取文本

- (void)processOcrAt:(UIImage *)image
{
    [self setTesseractImage:image];

    tesseract->Recognize(NULL);
    char* utf8Text = tesseract->GetUTF8Text();
    int conf = tesseract->MeanTextConf();

    NSArray *arr = [[NSArray alloc]initWithObjects:[NSString stringWithUTF8String:utf8Text],[NSString stringWithFormat:@"%d%@",conf,@"%"], nil]; …
Run Code Online (Sandbox Code Playgroud)

ocr tesseract ios xcode4.5 leptonica

14
推荐指数
1
解决办法
1万
查看次数

如何在iPhone上比较一个图像与另一个图像以确定它们是否相似一定比例?

我基本上想要拍摄iPhone或iPad 2上从相机拍摄的两张图像,并将它们相互比较,看看它们是否完全相同.显然由于光线等,图像永远不会完全相同,所以我想检查大约90%的兼容性.

我在这里看到的所有其他类似问题要么不适用于iOS,要么是用于在图像中定位对象.我只是想看看两个图像是否相似.

谢谢.

iphone xcode compare image uiimage

13
推荐指数
1
解决办法
1万
查看次数

iOS - 获取字母的"真实"高度

我正在尝试在UIView上布局文本.

(黄色区域是具有背景颜色的UILabel的框架).

当我使用sizeWithFont时,我得到了这个,它在字母上方有一个非常大的空间:

p with sizeWithFont

当我使用时font.pointSize我得到这个"我"这是好的 -

p与font.pointSize

但是 当我用它作为"p"时,我得到了精确的高度,但字母在底部绘制并裁剪.

p与font.pointSize

**我怎样才能获得仅在框架中居中的字形?**

谢谢

沙尼

uifont ios

12
推荐指数
1
解决办法
1万
查看次数

UIImage在缩放时变得模糊.为什么?(iOS 5.0)

当它被缩放时,UIImage总是变得模糊不清.如果让它保持清晰,我该怎么办?

- (UIImage *)rescaleImageToSize:(CGSize)size {
    CGRect rect = CGRectMake(0.0, 0.0, size.width, size.height);
    UIGraphicsBeginImageContext(rect.size);
    [self drawInRect:rect];  // scales image to rect
    UIImage *resImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return resImage;
}
Run Code Online (Sandbox Code Playgroud)

scale uiimage ios

12
推荐指数
2
解决办法
7703
查看次数

从iPhone上的PNG图像读取像素颜色值的简单方法?

有没有一种简单的方法来获得一个二维数组或类似的代表图像像素数据的东西?

我有黑白PNG图像,我只想读取某个坐标处的颜色值.例如,颜色值为20/100.

cocoa-touch objective-c ios

10
推荐指数
1
解决办法
1万
查看次数

如何从CGImage获取Raw像素数据

如何在缩放和移动后获取UIimage的像素数据,我想获得CGImage Pixel Data,然后从CGImage Pixel Data获取UIImage.我们可以这样做吗?

iphone objective-c

10
推荐指数
1
解决办法
2万
查看次数