我目前正在尝试获取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之间的坐标 - …
真的,真奇怪的错误
我有一个在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) 我想在图像上实现alpha渐变.从图像顶部的0.5 alfa到底部的0.0.欢迎任何建议,教程和链接.
在标记为复制或重复问题之前,请先阅读整个问题.
我能够在现有的情况下做到如下:
tesseract和处理图像leptonica.例如,如果输入是这张照片:
照片开始

照片结束
我想要的是能够为这张照片获得相同的准确度
没有生成块.
我用来初始化从图像中提取和提取文本的代码如下:
对于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) 我基本上想要拍摄iPhone或iPad 2上从相机拍摄的两张图像,并将它们相互比较,看看它们是否完全相同.显然由于光线等,图像永远不会完全相同,所以我想检查大约90%的兼容性.
我在这里看到的所有其他类似问题要么不适用于iOS,要么是用于在图像中定位对象.我只是想看看两个图像是否相似.
谢谢.
我正在尝试在UIView上布局文本.
(黄色区域是具有背景颜色的UILabel的框架).
当我使用sizeWithFont时,我得到了这个,它在字母上方有一个非常大的空间:

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

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

**我怎样才能获得仅在框架中居中的字形?**
谢谢
沙尼
当它被缩放时,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) 有没有一种简单的方法来获得一个二维数组或类似的代表图像像素数据的东西?
我有黑白PNG图像,我只想读取某个坐标处的颜色值.例如,颜色值为20/100.
如何在缩放和移动后获取UIimage的像素数据,我想获得CGImage Pixel Data,然后从CGImage Pixel Data获取UIImage.我们可以这样做吗?