2

有什么选择吗?我无法让它为 Monotouch 工作。似乎 AForge*.dll 缺少一些功能。现在,我正在研究 OpenCV,但对于这样一个简单的问题来说它太复杂了。但仍然很有趣:)

好吧,没有问题System.Drawing.Bitmap,我已经从github.com/mono/构建了它并且它有效。但是存在与 AForge 框架相关的错误。当我尝试通过Bitmap Apply (Bitmap image)from应用过滤器时AForge.Imaging.Filters.BaseFilter,出现错误:

错误 CS0584:内部编译器错误:找不到方法:'AForge.Imaging.UnmanagedImage.CollectActivePixels'。(CS0584) (项目名称)

另外,当我尝试使用AForge.Imaging.Filters.SepiaorInvert时,编译器找不到它们:

错误 CS0584:内部编译器错误:无法导入类型AForge.Imaging.Filters.Sepia' from AForge.Imaging,版本=2.2.4.0,文化=中性,PublicKeyToken=ba8ddea9676ca48b' (CS0584) (projectName)

有趣的是AForge.Imaging.Filters.Grayscale发现。

以下是产生这些错误的代码:

这会产生“无法导入类型”错误:

partial void showFilters (MonoTouch.Foundation.NSObject sender)
    {
        UIActionSheet sheet = new UIActionSheet ("Filters");
        // @TODO: I'll hardcode filters for now, but in future it should be refactored out.
        sheet.AddButton ("Grayscale");
        sheet.AddButton ("Sepia");
        sheet.AddButton ("Invert");
        sheet.Clicked += 
            (sndr, e) => {
            var ev = (UIButtonEventArgs)e;
            switch (ev.ButtonIndex) {
            case 0:
                imageView.Image = ImageProcessor.process (imageView.Image, new Grayscale(0.2125, 0.7154, 0.0721));
                break;
            case 1:
                imageView.Image = ImageProcessor.process (imageView.Image, new Sepia());
                break;
            case 2:
                imageView.Image = ImageProcessor.process (imageView.Image, new Invert());
                break;
            }
            imageView.Image.SaveToPhotosAlbum((image, error) => {
                var o = image as UIImage;
                Console.WriteLine("error:" + error);
            });
        };
        sheet.ShowInView (this.View);
    }

前 3 个函数产生“ Method not found: 'AForge.Imaging.UnmanagedImage.CollectActivePixels'. :

    #region methods
    static public Bitmap process (String fileName, IFilter filter)
    {
        if (File.Exists (fileName)) {
            Bitmap bitmap = Bitmap.FromFile (fileName);
            Bitmap image = (Bitmap) filter.Apply (bitmap);
            return image;
        } else {
            throw (new FileNotFoundException());
        }
    }

    static public Bitmap process (String fileName, FiltersSequence seq)
    {
        if (File.Exists (fileName)) {
            Bitmap image = Bitmap.FromFile (fileName);
            image = seq.Apply (image);
            return image;
        } else {
            throw (new FileNotFoundException());
        }
    }
    #region iOS
    static public UIImage process (UIImage capturedImage, IFilter filter)
    {
        Bitmap bitmap = getBitmapFromUIImage (capturedImage);
        Bitmap image = (Bitmap) filter.Apply (bitmap);
        UIImage result = getUIImageFromBitmap (image);
        return result;
    }

    static public Bitmap getBitmapFromUIImage (UIImage capturedImage)
    {
        NSData imageData = capturedImage.AsPNG();
        Byte[] byteArray = new Byte[imageData.Length];
        System.Runtime.InteropServices.Marshal.Copy (imageData.Bytes,
                                                     byteArray,
                                                     0,
                                                     Convert.ToInt32 (imageData.Length));
        MemoryStream stream = new MemoryStream (byteArray);
        Bitmap bitmap = new Bitmap (stream, false);
        return bitmap;
    }

    static public UIImage getUIImageFromBitmap (Bitmap bitmap)
    {
        Byte[] byteArray;
        MemoryStream stream = new MemoryStream();
        bitmap.Save(stream);
        stream.Close();
        byteArray = stream.ToArray();
        NSData imageData = NSData.FromArray(byteArray);
        return UIImage.LoadFromData(imageData);
    }
    #endregion iOS
    #endregion methods

}

以及完整的错误列表:

Error CS0584: Internal compiler error: Could not import type `AForge.Imaging.Filters.Sepia' from `AForge.Imaging, Version=2.2.4.0, Culture=neutral, PublicKeyToken=ba8ddea9676ca48b' (CS0584) (tryingImageProcessing)
Error CS0584: Internal compiler error: Could not import type `AForge.Imaging.Filters.Invert' from `AForge.Imaging, Version=2.2.4.0, Culture=neutral, PublicKeyToken=ba8ddea9676ca48b' (CS0584) (tryingImageProcessing)
Error CS0584: Internal compiler error: Method not found: 'AForge.Imaging.UnmanagedImage.CollectActivePixels'. (CS0584) (tryingImageProcessing)
Error CS0266: Cannot implicitly convert type `object' to `System.Drawing.Bitmap'. An explicit conversion exists (are you missing a cast?) (CS0266) (tryingImageProcessing)

我没有说最后一个错误,因为它很容易修复,但我不明白它为什么会出现。它哭泣着:

Bitmap image = ((BaseFilter) filter).Apply (bitmap);

以及我使用的每一行Apply.

这是项目本身(Monodevelop,压缩)。

答案: Monodevelop。未找到从程序集浏览器可见的方法。(CS0584)

4

0 回答 0