public void UpdatePhoto(Stream photoStream, Rect crop) { this.IsPhotoChanging = true; this.SetInProgress(true, ""); ImagePreprocessor.PreprocessImage(photoStream, VKConstants.ResizedImageSize, true, (Action<ImagePreprocessResult>)(resized => { Stream stream = resized.Stream; byte[] photoData = ImagePreprocessor.ReadFully(stream); stream.Close(); BackendServices.MessagesService.UpdateChatPhoto(this.ChatId, photoData, ImagePreprocessor.GetThumbnailRect((double)resized.Width, (double)resized.Height, crop), (Action<BackendResult<ChatInfoWithMessageId, ResultCode>>)(result => Execute.ExecuteOnUIThread((Action)(() => { if (result.ResultCode == ResultCode.Succeeded) { this._chatInformation.chat.photo_200 = result.ResultData.chat.photo_200; this.NotifyPropertyChanged<string>((Expression<Func<string>>)(() => this.Photo)); this.NotifyPropertyChanged<Visibility>((Expression<Func<Visibility>>)(() => this.PhotoPlaceholderVisibility)); this.NotifyPropertyChanged<bool>((Expression<Func<bool>>)(() => this.IsPhotoMenuEnabled)); } else GenericInfoUC.ShowBasedOnResult(result.ResultCode, "", (VKRequestsDispatcher.Error)null); this.SetInProgress(false, ""); this.IsPhotoChanging = false; })))); })); }
public void UploadUserPhoto(Stream stream, Rect rect) { if (this.IsSaving) { return; } this.IsSaving = true; this.SetInProgress(true, ""); ImagePreprocessor.PreprocessImage(stream, VKConstants.ResizedImageSize, true, (Action <ImagePreprocessResult>)(pres => { Stream stream1 = pres.Stream; byte[] numArray = (byte[])new byte[stream1.Length]; stream1.Read(numArray, 0, (int)stream1.Length); stream1.Close(); UsersService.Instance.SaveProfilePhoto(ImagePreprocessor.GetThumbnailRect((double)pres.Width, (double)pres.Height, rect), numArray, (Action <BackendResult <ProfilePhoto, ResultCode> >)(res => { this.IsSaving = false; this.SetInProgress(false, ""); if (res.ResultCode == ResultCode.Succeeded) { BaseDataManager.Instance.NeedRefreshBaseData = true; BaseDataManager.Instance.RefreshBaseDataIfNeeded(); } else { ExtendedMessageBox.ShowSafe(CommonResources.Error); } })); })); }
public void UploadPhoto(Stream photoDataStream, Action <BackendResult <Photo, ResultCode> > callback) { ImagePreprocessor.PreprocessImage(photoDataStream, VKConstants.ResizedImageSize, true, (Action <ImagePreprocessResult>)(pres => { Stream stream = pres.Stream; byte[] numArray = new byte[stream.Length]; stream.Read(numArray, 0, (int)stream.Length); stream.Close(); this.SetInProgress(true, ""); PhotosService.Current.UploadPhotoToAlbum(this._albumId, this._isGroup ? this._userOrGroupId : 0, numArray, (Action <BackendResult <Photo, ResultCode> >)(res => { this.SetInProgress(false, ""); if (res.ResultCode == ResultCode.Succeeded) { Execute.ExecuteOnUIThread((Action)(() => { Photo resultData1 = res.ResultData; EventAggregator current = EventAggregator.Current; PhotoUploadedToAlbum photoUploadedToAlbum = new PhotoUploadedToAlbum(); photoUploadedToAlbum.photo = resultData1; long pid = resultData1.pid; photoUploadedToAlbum.pid = pid; string str = resultData1.aid.ToString(); photoUploadedToAlbum.aid = str; current.Publish((object)photoUploadedToAlbum); if (string.IsNullOrEmpty(this.ThumbSrc)) { EventAggregator.Current.Publish((object)new PhotoSetAsAlbumCover() { aid = this._albumId, pid = resultData1.pid, Photo = resultData1 }); } else { if (this._albumPhotos.Count <= 1) { return; } Photo photo = this._albumPhotos[1].Photo; if (!(this.ThumbSrc == photo.photo_75) && !(this.ThumbSrc == photo.photo_130) && (!(this.ThumbSrc == photo.photo_604) && !(this.ThumbSrc == photo.photo_807)) && (!(this.ThumbSrc == photo.photo_1280) && !(this.ThumbSrc == photo.photo_2560) && (!(this.ThumbSrc == photo.src) && !(this.ThumbSrc == photo.src_small))) && (!(this.ThumbSrc == photo.src_big) && !(this.ThumbSrc == photo.src_xbig) && !(this.ThumbSrc == photo.src_xxbig))) { return; } Photo resultData2 = res.ResultData; EventAggregator.Current.Publish((object)new PhotoSetAsAlbumCover() { aid = this._albumId, Photo = resultData2, pid = resultData2.pid }); } })); } callback(res); })); })); }
private void InitCamera() { // ADD CAMERA SUPPORT _imagePreprocessor = new ImagePreprocessor(); _cameraHandler = CameraHandler.Instance; Handler threadLooper = new Handler(MainLooper); _cameraHandler.InitializeCamera(this, threadLooper, new ImageAvailableListener() { OnImageAvailableAction = (imageReader) => { Bitmap bitmap = _imagePreprocessor.PreprocessImage(imageReader.AcquireNextImage()); OnPhotoReady(bitmap); } }); }
internal void SetUserPhoto(Stream stream, Rect rect) { this._photoCropRect = rect; ImagePreprocessor.PreprocessImage(stream, 1500000, false, (Action <ImagePreprocessResult>)(imPR => Execute.ExecuteOnUIThread((Action)(() => { BitmapImage bitmapImage = new BitmapImage(); Stream stream1 = imPR.Stream; bitmapImage.SetSource(stream1); WriteableBitmap bmp = new WriteableBitmap((BitmapSource)bitmapImage); WriteableBitmap bitmap = bmp.Crop(new Rect() { Width = (double)bmp.PixelWidth * rect.Width, Height = (double)bmp.PixelHeight * rect.Height, Y = rect.Top * (double)bmp.PixelHeight, X = rect.Left * (double)bmp.PixelWidth }); try { if (!string.IsNullOrWhiteSpace(this._fullAvatarUri)) { File.Delete(this._fullAvatarUri); } using (IsolatedStorageFile storeForApplication = IsolatedStorageFile.GetUserStoreForApplication()) { MemoryStream memoryStream = new MemoryStream(); bitmap.SaveJpeg((Stream)memoryStream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 90); memoryStream.Position = 0L; this._fullAvatarUri = Guid.NewGuid().ToString(); ImageCache.Current.TrySetImageForUri("cropped" + this._fullAvatarUri, (Stream)memoryStream); stream.Position = 0L; using (IsolatedStorageFileStream storageFileStream = storeForApplication.OpenFile(this._fullAvatarUri, FileMode.Create, FileAccess.Write)) StreamUtils.CopyStream(stream, (Stream)storageFileStream, (Action <double>)null, (Cancellation)null, 0L); this.HavePhoto = true; } } catch { } })))); }
public override void Upload(Action completionCallback, Action <double> progressCallback = null) { Action action; Execute.ExecuteOnUIThread((Action)(() => { if (this.UploadState == OutboundAttachmentUploadState.Uploading) { return; } if (this.UploadState == OutboundAttachmentUploadState.Completed) { completionCallback(); } else { this.UploadState = OutboundAttachmentUploadState.Uploading; Stream stream = ImageCache.Current.GetCachedImageStream(this.LocalUrlBig); ImagePreprocessor.PreprocessImage(stream, VKConstants.ResizedImageSize, true, (Action <ImagePreprocessResult>)(pres => { Stream stream2 = pres.Stream; stream.Close(); byte[] bytes = ImagePreprocessor.ReadFully(stream2); stream2.Close(); this.UploadImpl(bytes, (action = (Action)(() => { if (this._uploadState == OutboundAttachmentUploadState.Completed && this._photo != null) { this.CleanupCache(); this._localUri = this._photo.src_big; } completionCallback(); })), progressCallback); })); } })); }