尝试显示位图时,“系统参数”例外参数无效

时间:2016-06-05 13:22:07

标签: c# image serialization memorystream

一直在尝试各种选项在图片框中显示矩形脸部捕捉,已经尝试了几天但感觉我接近这个代码

//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;                       
    }

1 个答案:

答案 0 :(得分:0)

我发现有两件事是错的。 1)Car Class中没有图像只有一个名字。然后Bitmap.FromStream使用整个Car类来获取图像,你需要忽略名称并只使用图像。

 <?php
 $host = 'localhost';
 $dbname   = 'project';
$username = 'root';
$password = '1234';
$charset = 'utf8';


  try {
 $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);

 $sql = 'SELECT subject,description,time,date FROM status ORDER BY time DESC';


$q = $pdo->query($sql);

$q->setFetchMode(PDO::FETCH_ASSOC);
 $usid = ($row['userID']);
 $sql1 = 'SELECT status.subject, status.description, status.time , status.date , status.stno , status.userID , tbl_users.userID , tbl_users.Fname , tbl_users.Lname 
  FROM status , tbl_users WHERE status.userID=tbl_users.userID ORDER BY status.time DESC';



 $q1 = $pdo->prepare($sql1);
$q1->execute([$usid]);
$q1->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die("Could not connect to the database $dbname :" . $e->getMessage());
}

 ?>