Ejemplo n.º 1
0
        internal static void SaveFace(Face face)
        {
            var filePath = Path.Combine (ImageStore.PicDir,face.OrgImage);
            if(!File.Exists(filePath))
                return;

            UIImage image = UIImage.FromFile(filePath);
            var path = UIBezierPath.FromOval(new RectangleF(0,0,face.Rect.Width,face.Rect.Height)).CGPath;
            UIGraphics.BeginImageContext(new SizeF(face.Width,face.Height));
            var c = UIGraphics.GetCurrentContext ();
            c.AddPath(path);
            c.Clip();
            //c.TranslateCTM(face.Width /2,face.Height /2 );
            //CGContextTranslateCTM (ctx, center.x, center.y);
            //c.RotateCTM(face.Roll);
            image.Draw(new RectangleF(face.Rect.Location,image.Size));
            //image.Draw(new RectangleF(PointF.Empty,image.Size));
            var bytes = UIGraphics.GetImageFromCurrentImageContext ().AsPNG();
            UIGraphics.EndImageContext ();
            NSError err;
            var newFilePath = Path.Combine (ImageStore.RoundedPicDir, face.Img);
            if(File.Exists(newFilePath))
                File.Delete(newFilePath);
            bytes.Save (newFilePath, false, out err);
            //CGContextTranslateCTM (ctx, -center.x, -center.y);
        }
Ejemplo n.º 2
0
        public static void parseFaces(FaceRestAPI.FaceAPI fd)
        {
            foreach (var photo in fd.photos) {
                //	http://graph.facebook.com/4926921/picture?type=large
                var url = photo.url;
                string id = url.Substring (26);
                id = id.Substring (0, id.IndexOf ("/"));
                int count = 0;

                lock (Database.Main)
                {
                    Database.Main.Execute("Delete from Face where FriendId = ?",id);
                }
                foreach (var tag in photo.tags) {
                    Face face = new Face ();
                    var increase = 1.1f;
                    face.FriendId = id;
                    var width = Math.Max ((photo.height * (tag.height / 100)) * increase, (photo.width * (tag.width / 100)) * increase);
                    face.Height = width;
                    face.Width = width;
                    var file = id + (count > 0 ? " -" + count : "") + ".png";
                    face.OrgImage =  id + ".png";
                    face.Img = file;
                    face.Cx = photo.width * ((tag.center.x) / 100);
                    face.Cy = photo.height * ((tag.center.y) / 100);
                    face.Roll = tag.roll;
                    lock (Database.Main)
                        Database.Main.Insert (face);
                    Graphics.SaveFace (face);
                    count++;

                }
            }
        }