【发布时间】:2016-06-05 13:22:06
【问题描述】:
一直在尝试各种选项来在图片框中显示矩形人脸捕获,已经尝试了几天,但感觉我已经接近此代码了
//preparing FaceRecord
fr.FacePosition = new FSDK.TFacePosition();
fr.FacialFeatures = new FSDK.TPoint[FSDK.FSDK_FACIAL_FEATURE_COUNT];
fr.Template = new byte[FSDK.TemplateSize];
fr.image = new FSDK.CImage();
fr.image = fr.image.CopyRect((int)(fr.FacePosition.xc - Math.Round(fr.FacePosition.w * 0.5)), (int)(fr.FacePosition.yc - Math.Round(fr.FacePosition.w * 0.5)), (int)(fr.FacePosition.xc + Math.Round(fr.FacePosition.w * 0.5)), (int)(fr.FacePosition.yc + Math.Round(fr.FacePosition.w * 0.5)));
Car car = new Car();
car.Name = "Temp";
MemoryStream stream = Serializer.SerializeToStream(car);
System.IO.File.WriteAllBytes("Temp.Jpeg", stream.ToArray());
using (var Stream = new MemoryStream(System.IO.File.ReadAllBytes("Temp.Jpeg")))
{
Car cab = (Car)Serializer.DeserializeFromStream(Stream);
var imageToSave = Bitmap.FromStream(Stream);
pictureBox2.Height = imageToSave.Height;
pictureBox2.Width = imageToSave.Width;
pictureBox2.Image = imageToSave;
}
参数无效异常就在上面
Var imageToSave = Bitmap.FromStream(Stream);
谁能给我任何关于下一步去哪里的建议?
序列化代码
public class Serializer
{
public static MemoryStream SerializeToStream(object o)
{
MemoryStream stream = new MemoryStream();
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, o);
return stream;
}
public static object DeserializeFromStream(MemoryStream stream)
{
IFormatter formatter = new BinaryFormatter();
stream.Seek(0, SeekOrigin.Begin);
object o = formatter.Deserialize(stream);
return o;
}
}
[Serializable]
public class Car
{
public string Name;
}
【问题讨论】:
-
你能发布你的序列化代码吗?
-
位图构造函数将抛出
ArgumentException,如果你传递的流不包含已知的图像格式,并且你没有序列化图像,你只是序列化一个对象输入Car。如果没有要加载的图像,如何加载图像? -
@theB 是一名 PHP 程序员,我正在尝试 C#,理解并尊重您的评论,只是觉得这个很难让我理解
-
道歉jackofnotrades,如果这被认为是敌对的,我正在尝试(并且显然失败)提出一个可能导致您得到答案的问题。 @jdweng 下面的回答更清楚地指出了我想要达到的目的。
-
@theB 表示尊重您的评论,从您的评论中认为我可能发现了我的错误,jdweng 然后确认了它,感谢您的意见。
标签: c# image serialization memorystream