我正在研究 GPUImage图书馆。我已设置特定过滤器将应用于 Collectionview 的 didselectitematindexpath 方法。这是我基于 GPUImage 库的第一个项目。我能够成功地在 GPUImageview 上应用过滤器,但是应用过滤器需要很多时间。请指导我,我怎样才能快速申请。
这是我的代码,
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[filter removeAllTargets];
if (indexPath.row==0) {
NSLog(@"Normal Filter");
}
else if (indexPath.row==1)
{
filter = [[GPUImageSepiaFilter alloc] init];
}
else if (indexPath.row==2)
{
filter = [[GPUImagePixellateFilter alloc] init];
}
else if (indexPath.row==3)
{
filter = [[GPUImagePixellatePositionFilter alloc] init];
}
else if (indexPath.row==4)
{
filter = [[GPUImagePolkaDotFilter alloc] init];
}
else if (indexPath.row==5)
{
filter = [[GPUImageHalftoneFilter alloc] init];
}
else if (indexPath.row==6)
{
filter = [[GPUImageCrosshatchFilter alloc] init];
}
else if (indexPath.row==7)
{
filter = [[GPUImageColorInvertFilter alloc] init];
}
else if (indexPath.row==8)
{
filter = [[GPUImageGrayscaleFilter alloc] init];
}
else if (indexPath.row==9)
{
filter = [[GPUImageMonochromeFilter alloc] init];
[(GPUImageMonochromeFilter *)filter setColor:(GPUVector4){0.0f, 0.0f, 1.0f, 1.f}];
}
else if (indexPath.row==10)
{
filter = [[GPUImageFalseColorFilter alloc] init];
}
else if (indexPath.row==11)
{
filter = [[GPUImageSoftEleganceFilter alloc] init];
}
else if (indexPath.row==12)
{
filter = [[GPUImageMissEtikateFilter alloc] init];
}
else if (indexPath.row==13)
{
filter = [[GPUImageAmatorkaFilter alloc] init];
}
else if (indexPath.row==14)
{
filter = [[GPUImageSaturationFilter alloc] init];
[(GPUImageSaturationFilter *)filter setSaturation:2.0];
}
else if (indexPath.row==15)
{
filter = [[GPUImageContrastFilter alloc] init];
[(GPUImageContrastFilter *)filter setContrast:1.5];
}
else if (indexPath.row==16)
{
filter = [[GPUImageBrightnessFilter alloc] init];
[(GPUImageBrightnessFilter *)filter setBrightness:0.6];
}
else if (indexPath.row==17)
{
filter = [[GPUImageLevelsFilter alloc] init];
}
else if (indexPath.row==18)
{
filter = [[GPUImageRGBFilter alloc] init];
}
else if (indexPath.row==19)
{
filter = [[GPUImageHueFilter alloc] init];
}
else if (indexPath.row==20)
{
filter = [[GPUImageWhiteBalanceFilter alloc] init];
}
else if (indexPath.row==21)
{
filter = [[GPUImageExposureFilter alloc] init];
}
else if (indexPath.row==22)
{
filter = [[GPUImageSharpenFilter alloc] init];
}
else if (indexPath.row==23)
{
filter = [[GPUImageUnsharpMaskFilter alloc] init];
}
else if (indexPath.row==24)
{
filter = [[GPUImageGammaFilter alloc] init];
}
else if (indexPath.row==25)
{
filter = [[GPUImageToneCurveFilter alloc] init];
[(GPUImageToneCurveFilter *)filter setBlueControlPoints:[NSArray arrayWithObjects:[NSValue valueWithCGPoint:CGPointMake(0.0, 0.0)], [NSValue valueWithCGPoint:CGPointMake(0.5, 0.5)], [NSValue valueWithCGPoint:CGPointMake(1.0, 0.75)], nil]];
}
else if (indexPath.row==26)
{
filter = [[GPUImageHighlightShadowFilter alloc] init];
}
else if (indexPath.row==27)
{
filter = [[GPUImageHazeFilter alloc] init];
}
else if (indexPath.row==28)
{
filter = [[GPUImageAverageColor alloc] init];
}
else if (indexPath.row==29)
{
filter = [[GPUImageLuminosity alloc] init];
}
else if (indexPath.row==30)
{
filter = [[GPUImageHistogramFilter alloc] initWithHistogramType:kGPUImageHistogramRGB];
}
else if (indexPath.row==31)
{
filter = [[GPUImageLuminanceThresholdFilter alloc] init];
}
else if (indexPath.row==32)
{
filter = [[GPUImageAdaptiveThresholdFilter alloc] init];
}
else if (indexPath.row==33)
{
filter = [[GPUImageAverageLuminanceThresholdFilter alloc] init];
}
else if (indexPath.row==34)
{
filter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0.0, 0.0, 1.0, 0.25)];
}
[sourcePicture addTarget:filter];
[filter addTarget:self.vwGPUImagview];
[sourcePicture processImage];
}
输出:-
编辑:- 当我编写 [filter removeAllTarget] 时,一些过滤器不起作用。如果我删除它然后它完全工作。我的错误在哪里?
编辑 2:- Demo Link
最佳答案
根据提供的代码,您在这里做的一些事情确实会减慢速度。首先,您有一个显然无用的 GPUImageVideoCamera,您重新创建了多次。可以删除。
其次,每次要显示一个单元格时,您都会基于 UIImage 创建一个新的 GPUImagePicture。这样做真的很慢。相反,尝试使用单个共享图像并在显示单元格时将其换出。此外,使用 -forceProcessingAtSize: 将过滤器大小限制为单元格中缩略图的大小。过滤一个巨大的图像是没有意义的,只显示一个小缩略图。
最后,正如我在上面指出的那样,每次换入新滤镜时,都会移除滤镜的输出,但不会移除图像的输出。这意味着您交换到的每个滤镜都会添加为图像的输出,但不会被删除。您的图像将建立越来越多的输出过滤器列表,并且处理速度会越来越慢。在删除之前过滤器的所有输出的同时,从图片中删除所有输出。
您还可以在您的过滤器上使用 -forceProcessingAtSize: 将它们限制为仅显示完整显示的大小,这可能仍小于您的源图像。
关于ios - GPUImage 花时间应用过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37006761/
对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
刚入门rails,开始慢慢理解。有人可以解释或给我一些关于在application_controller中编码的好处或时间和原因的想法吗?有哪些用例。您如何为Rails应用程序使用应用程序Controller?我不想在那里放太多代码,因为据我了解,每个请求都会调用此Controller。这是真的? 最佳答案 ApplicationController实际上是您应用程序中的每个其他Controller都将从中继承的类(尽管这不是强制性的)。我同意不要用太多代码弄乱它并保持干净整洁的态度,尽管在某些情况下ApplicationContr
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我需要检查DateTime是否采用有效的ISO8601格式。喜欢:#iso8601?我检查了ruby是否有特定方法,但没有找到。目前我正在使用date.iso8601==date来检查这个。有什么好的方法吗?编辑解释我的环境,并改变问题的范围。因此,我的项目将使用jsapiFullCalendar,这就是我需要iso8601字符串格式的原因。我想知道更好或正确的方法是什么,以正确的格式将日期保存在数据库中,或者让ActiveRecord完成它们的工作并在我需要时间信息时对其进行操作。 最佳答案 我不太明白你的问题。我假设您想检查
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
这个问题在这里已经有了答案:Railsformattingdate(4个答案)关闭4年前。我想格式化Time.Now函数以显示YYYY-MM-DDHH:MM:SS而不是:“2018-03-0909:47:19+0000”该函数需要放在时间中.现在功能。require‘roo’require‘roo-xls’require‘byebug’file_name=ARGV.first||“Template.xlsx”excel_file=Roo::Spreadsheet.open(“./#{file_name}“,extension::xlsx)xml=Nokogiri::XML::Build
我正在尝试解析一个CSV文件并使用SQL命令自动为其创建一个表。CSV中的第一行给出了列标题。但我需要推断每个列的类型。Ruby中是否有任何函数可以找到每个字段中内容的类型。例如,CSV行:"12012","Test","1233.22","12:21:22","10/10/2009"应该产生像这样的类型['integer','string','float','time','date']谢谢! 最佳答案 require'time'defto_something(str)if(num=Integer(str)rescueFloat(s
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的