有什么选择吗?我无法让Monotouch工作。好像AForge * .dll中缺少一些功能。 现在,我正在研究OpenCV,但这对于这么简单的问题来说太复杂了。但仍然非常有趣:)
嗯,System.Drawing.Bitmap
没有问题,我是从github.com/mono/构建的,但它确实有效。但是与AForge框架有关的错误。当我尝试从Bitmap Apply (Bitmap image)
通过AForge.Imaging.Filters.BaseFilter
应用过滤器时,我收到错误:
错误CS0584:内部编译器错误:找不到方法:'AForge.Imaging.UnmanagedImage.CollectActivePixels'。 (CS0584)(projectName)
此外,当我尝试使用AForge.Imaging.Filters.Sepia
或Invert
时,编译器找不到它们:
错误CS0584:内部编译器错误:无法导入类型
AForge.Imaging.Filters.Sepia' from
AForge.Imaging,Version = 2.2.4.0,Culture = neutral,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个函数产生“找不到方法:'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
的每一行。
This is the project itself (Monodevelop, zipped).
答案: Monodevelop. Method that visible from Assembly Browser not found. (CS0584)