4

UIImage にさまざまな効果を追加したいと考えています。現在、GUIImage ライブラリを使用しようとしています。https://github.com/BradLarson/GPUImage しかし、提供されている例のほとんどを実行できません。私にとって唯一の実例はFilterShowcaseです。

しかし、問題は、カメラでしか機能しないことです。私が欲しいのは、静的な画像を UIImageView にロードし、それらのフィルターを適用することです。

やってみましたが、できませんでした。

やってみたのはこんな感じ

  - (void)setupFilter;
{
//    videoCamera = [[GPUImageVideoCamera alloc]  initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
////    videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionFront];
//    videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait;


UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 350)];

imgView.Image=[UIImage imageNamed:@"WID-small.jpg"];

[self.view addSubview:imgView];

BOOL needsSecondImage = NO;

switch (filterType)
{
    case GPUIMAGE_SEPIA:
    {
        self.title = @"Sepia Tone";
        self.filterSettingsSlider.hidden = NO;

        [self.filterSettingsSlider setValue:1.0];
        [self.filterSettingsSlider setMinimumValue:0.0];
        [self.filterSettingsSlider setMaximumValue:1.0];

        filter = [[GPUImageSepiaFilter alloc] init];

        sourcePicture = [[GPUImagePicture alloc] initWithImage:imgView.image smoothlyScaleOutput:YES];
        [sourcePicture processImage];            
        [sourcePicture addTarget:filter];




    }; break;

実際に私がやろうとしたことは、videoCameraの代わりに静止画像をロードすることです。しかし、うまくいきません。誰かが私を助けることができれば、それは大歓迎です。

4

1 に答える 1

12

まず、他のサンプル アプリケーションがビルドされない理由がいくつかあります。この回答に記載されているように、GPUImage フレームワーク プロジェクトではなく、Xcode ウィンドウの左上でアプリケーションのスキームが選択されていることを確認してください。変更しても問題が解決しない場合は、Xcode を終了し、関連するプロジェクト ディレクトリを DerivedData ディレクトリから削除して、Xcode を再起動します。最近の Xcode バージョンのバグにより、これが必要になる場合があります。

画像のフィルタリングについては、プロジェクトのドキュメントで説明されています。これは、Readme.md ファイルと上記のリンク先のページにあります。特に、「静止画像の処理」というタイトルのセクションを参照してください。

静止画像を処理して結果を作成するには、いくつかの方法があります。これを行う最初の方法は、静止画像ソース オブジェクトを作成し、フィルター チェーンを手動で作成することです。

UIImage *inputImage = [UIImage imageNamed:@"Lambeau.jpg"];

GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];
GPUImageSepiaFilter *stillImageFilter = [[GPUImageSepiaFilter alloc] init];

[stillImageSource addTarget:stillImageFilter];
[stillImageSource processImage];

UIImage *currentFilteredVideoFrame = [stillImageFilter imageFromCurrentlyProcessedOutput];

画像に適用したい単一のフィルターの場合、次のように簡単に実行できます。

GPUImageSepiaFilter *stillImageFilter2 = [[GPUImageSepiaFilter alloc] init];
UIImage *quickFilteredImage = [stillImageFilter2 imageByFilteringImage:inputImage];

SimpleImageFilter サンプル アプリケーションは、これを行う方法をより詳細に示しています。

于 2012-07-16T18:30:06.997 に答える