您的位置:首页 > 产品设计 > UI/UE

How to add multiple filters to UIImage GPUImage?

2015-10-30 11:27 197 查看
from: http://www.scriptscoop.net/t/174138f67b0f/ios-how-to-add-multiple-filters-to-uiimage-gpuimage.html
I noticed a lot of people asking questions about linking filters with GPUImage. I can't quite figure out how to do it succinctly. Finally got it working tonight. Just wanted to share my code so people can link to the solution.

Related questions:

How to correctly alternate between different filters of UIImage (GPUImage)

Add multiple filters to cardboard app rally


1 answer

By chrisallick


UIImage *faceImage = [UIImage imageNamed:@"469453586_640.jpg"];
UIImageView *face = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, faceImage.size.width/2.0, faceImage.size.height/2.0)];
[face setImage:faceImage];
[self.view addSubview:face];

GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:faceImage];

GPUImageBrightnessFilter *brightnessFilter = [[GPUImageBrightnessFilter alloc] init];
[brightnessFilter setBrightness:.15];
GPUImageGrayscaleFilter *grayscaleFilter = [[GPUImageGrayscaleFilter alloc] init];

GPUImagePosterizeFilter *posterizeFilter = [[GPUImagePosterizeFilter alloc] init];
[posterizeFilter setColorLevels:1];

[stillImageSource addTarget:brightnessFilter];
[brightnessFilter addTarget:grayscaleFilter];
[grayscaleFilter addTarget:posterizeFilter];

// these need to be changed if you change the order of your filters
//    [brightnessFilter useNextFrameForImageCapture];
//    [grayscaleFilter useNextFrameForImageCapture];
[posterizeFilter useNextFrameForImageCapture];

[stillImageSource processImage];

[face setImage: [posterizeFilter imageFromCurrentFramebuffer]];



2 similar answers β

By ophychius

I have an app that sort of does the same, and what I do is that I keep my baseImage at hand, and once I am done applying the filter and showing the image with filter I reset everything. The moment a user selects a different filter I use the baseImage again
to create the new filtered image and show it.

So in this example you could for example move the [sourcePicture removeAllTargets]; to right after this [self.view addSubview:filterView];

That saves you work when you want to apply a new filter. Also, there is a quicker (dirtier way to filter a picture when you are working with an image that already exists. I got this from the documentation that came with GPUImage and it works like a charm.
GPUImageSketchFilter *stillImageFilter2 = [[GPUImageSketchFilter alloc] init];
tmp = [stillImageFilter2 imageByFilteringImage:[self baseImage]];
[self.imageView setImage: tmp];
tmp = nil;


Hope it helps you on your way.

By user4211235

You can sometimes get hints/code for your apps via the open source repo for the Rally App Catalog. For your example, there is available source code for the Release Planning App. Reviewing the source code, you can see that the Filter Picker is defined by the
following requirement defined in the source:

Rally.ui.gridboard.plugin.GridBoardCustomFilterControl


And this is incorporated into the board by adding its plugin to the board configuration.

It's tempting to add this to a Simple Grid example, exactly as the Release planning board does, which I tried doing as follows:
<!DOCTYPE html>
<html>
<head>
<title>Rally Example: Simple Board</title>

<script type="text/javascript" src="/apps/2.0rc3/sdk.js"></script>

<script type="text/javascript">
Rally.onReady(function () {
Ext.define('Rally.example.SimpleBoard', {
extend: 'Rally.app.App',
requires: [
'Rally.ui.gridboard.plugin.GridBoardCustomFilterControl'
],

launch: function() {
this.add({
xtype: 'rallycardboard',
types: ['User Story'],
attribute: 'ScheduleState',
context: this.getContext(),
readOnly: true,
cardConfig: {
showIconsAndHighlightBorder: false,
editable: false
},
plugins: [
{
ptype: 'rallygridboardcustomfiltercontrol',
filterChildren: false,
filterControlConfig: {
margin: '3 9 3 30',
blackListFields: ['PortfolioItemType', 'Release'],
whiteListFields: [this._milestonesAreEnabled() ? 'Milestones' : ''],
modelNames: ['HierarchicalRequirement']
}
}
]
});
}
});

Rally.launchApp('Rally.example.SimpleBoard', {
name:"Rally Example: Simple Board",
parentRepos:""
});

});
</script>

<style type="text/css">
.app {
/* Add app styles here */
}

</style>
</head>
<body>
</body>
</html>


However, if you try to load the app in this way, you'll get a 404 when it looks for the
Rally.ui.gridboard.plugin.GridBoardCustomFilterControl
class.

Looking at the AppSDK2.0rc3 docs, this plugin does not appear to be available under the Rally.ui.cardboard.plugins.* tree that's bundled into the SDK. See screenshot here:

AppSDK2.0rc3 screenshot excerpt:



Nor does it appear that the Rally.ui.gridboard.plugin.* tree is bundled into the AppSDK. It is likely that the class is however, available to the Rally UI via a different javascript bundle (non-public) that the Rally
developers use.

Perhaps it would be feasible for Rally Engineering to bundle this plugin into the AppSDK so that customer developers could use it - perhaps file a Feature Request on Rally Ideas or something like that to see if this is achievable.



how to add
multiple filters to mapbox leaflet maps
nrutasVotes: 0Relevancy: 90%
I have a working mapbox/leaflet map and I can filter based on dropdowns but only one of them will work, not sure of the syntax (or if it's possible) to combine filters? I basically have a real estate
map populated with json data which includes property types and neighborhoods. need to combine the possible filters, so selecting a different property type won't erase the neighborhood filter.

ng-repeat:
how to add multiple filters?

SpearfisherVotes: 1Relevancy: 87%

I'd like to use multiple filters on the same item for an ng-repeat. The idea is that for each job below I have different properties like location and salary and I'd like to be able to filter the results with both criteria. So far, I've tried this. But it's
obviously not working. Does anyone have a clue how to fix this? Thanks

UISearchDisplayController:
Add multiple filters to an existing filter

AlexRVotes: 0Relevancy: 84%

I am using a UISearchDisplayController the default way to filter the cells of a UITableViewController by its text values (e.g. to show only the cells which start with the letters 'ab'). The values in the cells of the table view are filled by a NSFetchedResultsController.
In addition to this text based filtering, I would like to add additional filtering capabilities based on the numeric range of the items (e.g.

How
can I get a UIImage from GPUImage camera?

Aaron BratcherVotes: 2Relevancy: 81%

I know I can use the still camera's capturePhotoAsImageProcessedUpToFilter method, but it gives a shutter click sound and I still have some processing to do so I don't want it to sound yet. I tried using a filter's imageFromCurrentFramebuffer method, but that
is always turning nil.

Proper
way to rotate UIImage with GPUImage

kevVotes: 3Relevancy: 78%

I want to rotate a large UIImage using GPUImage because it's so much faster than core graphics, at least on iOS devices. Here's what I'm doing. The only problem is that I get a strip of white pixels on the end (the black strips are not part of the image). How
do I get rid of that white strip? Note. I am using other filters on top of the rotation filter. Maybe there's an issue in conjunction with other filters.

How
do I apply apply multiple filters that require multiple images using GPUImage

user379468Votes: 0Relevancy: 75%

I'm using GPUImage 0.1.2. Currently I have a GPUImageChromaKeyBlendFilter that is bing applied to GPUImage picture (picture 1) and that picture is in turn added to another picture (picture 2) So in essence picture one is composited over picture 2. Now in addition
I also want to apply a mask filter to picture 1, but I cant seem to figure out how to chain the filters correctly, I've looked into using filter groups, but it hasn't gotten me any closer.

Multiple
Filters using GPUImage Library

Helium3Votes: 0Relevancy: 72%

I am trying to apply 3 filters to an image. One rgbFilter which is has its values constant, a brightness filter and a saturation filter, both of which should be able to be modified and the image should update. I have followed the advice here. I have setup a
UIView using IB and set its class to GPUImageView. For some reason the image doesnt show. My steps are as follows. and then I call this which sets the constant values on the rgb filter I setup my filters before this using.

Generating
UIImage from GPUImage video frame

John Michael ZorkoVotes: 0Relevancy: 69%

I'm trying to generate a UIImage from a video frame captured by GPUImage. I've done a lot of AVFoundation video work, but i'm new to using GPUImage. I've subclassed GPUImageVideoCamera and added this method, but the UIImage is always nil. If anyone can tell
me where i've gone so horribly wrong, i'd be very appreciative! { [super processVideoSampleBuffer. sampleBuffer]; // to let GPUImage do it's processing first

Convolution
UIImage with GPUImage framework

TonyVotes: 0Relevancy: 66%

I'm trying to use GPUImage3x3ConvolutionFilter of GPUImage framework but is not working. This is my code, I only get a white image. I'm also try changing. for.

iOS
Invert Colors on Application

Emrah AyanogluVotes: 1Relevancy: 63%

I'd like to invert all colors in my application like Settings > Accessibility > Invert Colors. Is there a way to make this stuff in a programmatically way in iOS such using CALayer or Filters like GPUImage or CoreImage?

xcode5:
how can I save and load an image?

user3550084Votes: -1Relevancy: 60%

I'm developing an app, where I can apply filters on an image. I want to create an undo button which resets the original image in the imageView.The solution is that I just save the original image in it's own UIImage object before I apply any filters to it. This
way I can just go back to that in my undo method. Does somebody know how I can do this?

How
to apply HSB color filters to UIImage

saerosVotes: 2Relevancy: 57%

I've been struggling for a few days for a project on UIImage colorization.The idea is that the app will embark a set of images that I will have to colorize with values retrieved from a webservice. Some sort of themes if you wish. The designer I work with gave
me a background image on all of his Photoshop values. The first problem is that Photoshop uses HSL and iOS uses HSB. So the first challenge was to translate the values from Photoshop. Photoshop HSL.

Add
multiple UIImage copies using UIStepper

user3156776Votes: 0Relevancy: 54%

I want to add/delete images in a view using a UIStepper. So every time you press the '+' the same image is copied within the same viewController, still being able to move/rotate every copy. I have something like this. but this does not work because it just
replaces the previous image. Is there a proper way to copy the same image multiple times using the UIStepper?

JQuery
DataTables multiple filters

aiguoferVotes: 0Relevancy: 51%

I have a table to display the raw data from a Rickshaw graph and I want to update it whenever I use the Rickshaw controls. Currently, here's the relevant code. The problem with this is that each time it's going to redraw, in the worst case it has to run through
the whole filter. Is there a way that I could add each filter separately (one for the slider and one for the legend)?

How
to add multiple route filters in Laravel 4.2 while using role:permission pattern?

Ali GajaniVotes: 0Relevancy: 48%

I am having issues with using multiple route filters in Laravel 4.2 while using the pattern role. permission. I've attached my code below. This doesn't work at all. When I change roles, it always give one 403 unauthorized. I want both moderator and administrator
to access this route. Perhaps there's a way to tell Laravel, "if the logged in user is either an administrator OR a moderator, then let them access this route". This is my role filter.

Adding
multiple filters to jquery find

nexuscreatorVotes: 0Relevancy: 45%

I am extending this question.I have this following code. How can I add filter to remove disabled input fields and having tabindex greater than 0? So far I have tried combining with .not('. disabled') and .not('input[tabindex>"0"]'), but those are not working.

Objectify
multiple filters doesn´t work with cron job

WeiniVotes: 0Relevancy: 42%

I´m working with objectify on appengine, I tried to add a cron job to delete all temp entities which are older than an hour. but i always get an Exception when executing the cron job on the appengine server. does anybody know why this happens? The job works
if I remove.

Angularfire
and jQM: Multiple filters not working

ivyVotes: 0Relevancy: 39%

I'm using Angularfire with jQuery Mobile (mostly for the CSS). I'm working on a website where you can keep track of your books, which are stored in a Firebase. I have a page (using jQM's page navigation) where all my books are listed in a listview, and the
search/filter works perfectly fine. The problem starts when I add another page with a different listview and search bar to search through the books I've read. The search bar on the second page doesn't work, even when the first one does.

Play
Framework Multiple filters in Global.java

max1221Votes: 2Relevancy: 36%

I'm using Play Framework 2.3.2 (Java version) I was wondering how I would go about adding multiple filters to the filters() override in Global.java? I have this to enable the CSRF Filter. and I'd like to now also add the Gzip filter. What's the correct syntax
to use to have both the CSRF filter and GZIP compression? It's described here. http. //www.playframework.com/documentation/2.3.x/GzipEncoding but it doesn't say how to add that as a filter when one already exists. Thanks in advance!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: