//todo: make this method for one or multiple files protected async Task <ICollection <Models.Image> > HandleFileSelected(IFileListEntry[] files) { Models.Image _image = new Models.Image(); file = files.FirstOrDefault(); using (MemoryStream ms = new MemoryStream((int)file.Size + 1)) { await file.Data.CopyToAsync(ms); _image.Data = ms.ToArray(); } _image.ImageName = file.Name; string byte64 = Convert.ToBase64String(_image.Data); int extensionIndex = _image.ImageName.IndexOf('.') + 1; string extension = _image.ImageName.Remove(0, extensionIndex); ImagesData.Add(new ImageData() { name = _image.ImageName, string64Data = new string("data:image/" + extension + "; base64," + byte64) }); await ImagesDataChanged.InvokeAsync(ImagesData); ModelImages.Add(_image); _image = new Models.Image(); return(ModelImages); }
public HttpResponseMessage upload() { string fileName = null; var httpRequest = HttpContext.Current.Request; var postedFiles = httpRequest.Files["Image"]; fileName = new String(Path.GetFileNameWithoutExtension(postedFiles.FileName) .Take(10).ToArray()).Replace(" ", "-"); fileName = fileName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFiles.FileName); var filepath = HttpContext.Current.Server.MapPath("~/Images/" + fileName); postedFiles.SaveAs(filepath); using (DbModel db = new DbModel()) { ImagesData data = new ImagesData() { Name = httpRequest["Name"], Description = httpRequest["Description"], IsFeatured = false, IndexPage = true, ImageUrl = fileName }; db.ImagesDatas.Add(data); db.SaveChanges(); } return(Request.CreateResponse(HttpStatusCode.Created)); }
private static void WriteCompressIPframes(String outFile, ImagesData imgs) { FileStream fs = new FileStream(outFile, FileMode.Create); BinaryWriter writer = new BinaryWriter(fs); writer.Write(imgs.Height); writer.Write(imgs.Width); writer.Write(imgs.IFrameGap); writer.Write(imgs.EncodedFrames.Length); for (int i = 0; i < imgs.EncodedFrames.Length; ++i) { writer.Write(imgs.EncodedFrames[i].Length); writer.Write(imgs.EncodedFrames[i]); } writer.Close(); fs.Close(); }
public static Bitmap[] DecompressIPFrames(string inFile) { ImagesData data = ReadCompressIPframes(inFile); int numOfFrames = data.EncodedFrames.Length; var bms = new Bitmap[numOfFrames]; var mpeg = new MPEG(data.Height, data.Width); for (int i = 0; i < numOfFrames; ++i) { if (i % data.IFrameGap == 0) { bms[i] = mpeg.Decompress(data.EncodedFrames[i], MPEG.FrameType.I); } else { bms[i] = mpeg.Decompress(data.EncodedFrames[i], MPEG.FrameType.P); } } return(bms); }
/**************************************************** OTHER METHODS ******************************************************/ /// <summary> /// <para>parses and returns the FeedData in the form of list</para> /// </summary> /// <param name="ParsedJson"></param> /// <returns></returns> private List <FeedData> ParseFeeds(dynamic ParsedJson) { // CREATE FEEDDATA LIST List <FeedData> Data = new List <FeedData>(); foreach (dynamic Post in ParsedJson.data) { // CREATE FEEDDATA OBJECT FeedData Feed = new FeedData(); // CREATE ATTRIBUTION OBJECT; if (Post.attribution == null) { Feed.Attribution = null; } else { AttributionData Attribution = new AttributionData(); Attribution.Website = Post.Attribution.website; Attribution.ItunesUrl = Post.Attribution.itunes_url; Attribution.Name = Post.Attribution.name; Feed.Attribution = Attribution; } // SET TAGS List <String> Tags = new List <String>(); foreach (dynamic Tag in Post.tags) { Tags.Add(Tag.ToString()); } Feed.Tags = Tags; // SET TYPE Feed.Type = Post.type; // SET LOCATION if (Post.location == null) { Feed.Location = null; } else { LocationData Location = new LocationData(); Location.Id = Post.location.id; Location.Latitude = Post.location.latitude; Location.Longitude = Post.location.longitude; Location.Name = Post.location.name; Feed.Location = Location; } // SET COMMENTS CommentData Comments = new CommentData(); Comments.Count = Post.comments.count; List <Comment> CommentData = new List <Comment>(); foreach (dynamic EachComment in Post.comments.data) { // CREATE COMMENT OBJECT Comment Comment = new Comment(); Comment.CreatedTime = new DateTime(long.Parse(EachComment.created_time.ToString())); Comment.Id = EachComment.id; Comment.Text = EachComment.text; // CREATE USER OBJECT User CommentedBy = new User(); CommentedBy.UserName = EachComment.from.username; CommentedBy.ProfilePicture = EachComment.from.profile_pciture; CommentedBy.Id = EachComment.from.id; CommentedBy.FullName = EachComment.from.full_name; // ASSOCIATE COMMENT WITH USER Comment.From = CommentedBy; // ADD COMMENT TO THE LIST CommentData.Add(Comment); } Comments.Data = CommentData; Feed.Comments = Comments; // SET FILTER Feed.Filter = Post.filter; // SET CREATED TIME Feed.CreatedTime = new DateTime(long.Parse(Post.created_time.ToString())); // SET LINK Feed.Link = Post.link; // SET LIKES LikesData Likes = new LikesData(); Likes.Count = Post.likes.count; List <User> LikedByUsers = new List <User>(); foreach (dynamic EachLike in Post.likes.data) { // CREATE USER OBJECT User LikedBy = new User(); LikedBy.UserName = EachLike.username; LikedBy.ProfilePicture = EachLike.profile_picture; LikedBy.Id = EachLike.id; LikedBy.FullName = EachLike.full_name; // ADD USER TO THE LIST LikedByUsers.Add(LikedBy); } Likes.Data = LikedByUsers; Feed.Likes = Likes; // SET VIDEO if (Feed.Type.Equals("video")) { VideosData VideoData = new VideosData(); LowResolutionVideo LRVideo = new LowResolutionVideo(); LRVideo.url = Post.videos.low_resolution.url; LRVideo.width = Post.videos.low_resolution.width; LRVideo.height = Post.videos.low_resolution.height; VideoData.LowResolution = LRVideo; StandardResolutionVideo SRVideo = new StandardResolutionVideo(); SRVideo.url = Post.videos.standard_resolution.url; SRVideo.width = Post.videos.standard_resolution.width; SRVideo.height = Post.videos.standard_resolution.height; VideoData.StandardResolution = SRVideo; Feed.Videos = VideoData; } else { Feed.Videos = null; } // SET IMAGES ImagesData Images = new ImagesData(); StandardResolutionImage SRImage = new StandardResolutionImage(); SRImage.url = Post.images.standard_resolution.url; SRImage.width = Post.images.standard_resolution.width; SRImage.height = Post.images.standard_resolution.height; Images.StandardResolution = SRImage; ThumbnailImage TImage = new ThumbnailImage(); TImage.url = Post.images.thumbnail.url; TImage.width = Post.images.thumbnail.width; TImage.height = Post.images.thumbnail.height; Images.Thumbnail = TImage; LowResolutionImage LRImage = new LowResolutionImage(); LRImage.url = Post.images.low_resolution.url; LRImage.width = Post.images.low_resolution.width; LRImage.height = Post.images.low_resolution.height; Images.LowResolution = LRImage; Feed.Images = Images; // SET CAPTIONS CaptionData Caption = new CaptionData(); if (Post.caption != null) { Caption.CreratedTime = new DateTime(long.Parse(Post.caption.created_time.ToString())); Caption.Text = Post.caption.text; Caption.Id = Post.caption.id; User CaptionedBy = new User(); CaptionedBy.UserName = Post.caption.from.username; CaptionedBy.ProfilePicture = Post.caption.from.profile_pciture; CaptionedBy.Id = Post.caption.from.id; CaptionedBy.FullName = Post.caption.from.full_name; Caption.From = CaptionedBy; } Feed.Caption = Caption; // SET TAGGED USER List <TaggedUser> UserInPhotos = new List <TaggedUser>(); if (Post.users_in_photo != null) { foreach (dynamic UserTag in Post.users_in_photo) { // CREATE TAGGED USER OBJECT TaggedUser TUser = new TaggedUser(); // SET USER User TaggedUser = new User(); TaggedUser.UserName = UserTag.user.username; TaggedUser.FullName = UserTag.user.full_name; TaggedUser.Id = UserTag.user.id; TaggedUser.ProfilePicture = UserTag.user.profile_picture; TUser.User = TaggedUser; // SET POSITION Position TagPosition = new Position(); TagPosition.x = float.Parse(UserTag.position.x.ToString()); TagPosition.y = float.Parse(UserTag.position.y.ToString()); TUser.Position = TagPosition; // ADD TO LIST UserInPhotos.Add(TUser); } } Feed.UsersInPhoto = UserInPhotos; // SET USER LIKE Feed.UserHasLiked = Post.user_has_liked; // SET ID Feed.Id = Post.id; // SET USER User FeedBy = new User(); FeedBy.UserName = Post.user.username; FeedBy.Website = Post.user.webste; FeedBy.ProfilePicture = Post.user.profile_picture; FeedBy.FullName = Post.user.full_name; FeedBy.Bio = Post.user.bio; FeedBy.Id = Post.user.id; Feed.User = FeedBy; // ADD FEED TO LIST Data.Add(Feed); } return(Data); }
public void AdjustScale() { Vector2 scale = ImagesData.AspectRatio(imageInfo.width, imageInfo.height); scalerObject.localScale = new Vector3(scale.x, scale.y, 1f); }