コード例 #1
0
        public async Task <TLMessage25> GetPhotoMessage(StorageFile file)
        {
            var volumeId = TLLong.Random();
            var localId  = TLInt.Random();
            var secret   = TLLong.Random();

            var fileLocation = new TLFileLocation
            {
                VolumeId = volumeId,
                LocalId  = localId,
                Secret   = secret,
                DCId     = new TLInt(0),    //TODO: remove from here, replace with FileLocationUnavailable
                //Buffer = p.Bytes
            };

            var fileName = String.Format("{0}_{1}_{2}.jpg",
                                         fileLocation.VolumeId,
                                         fileLocation.LocalId,
                                         fileLocation.Secret);

            var stream = await file.OpenReadAsync();

            var resizedPhoto = await ResizeJpeg(stream, Constants.DefaultImageSize, file.DisplayName, fileName);

            var photoSize = new TLPhotoSize
            {
                Type     = TLString.Empty,
                W        = new TLInt(resizedPhoto.Width),
                H        = new TLInt(resizedPhoto.Height),
                Location = fileLocation,
                Size     = new TLInt(resizedPhoto.Bytes.Length)
            };

            var photo = new TLPhoto33
            {
                Id         = new TLLong(0),
                AccessHash = new TLLong(0),
                Date       = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now),
                Sizes      = new TLVector <TLPhotoSizeBase> {
                    photoSize
                },
            };

            var media = new TLMessageMediaPhoto28 {
                Photo = photo, Caption = TLString.Empty, File = resizedPhoto.File
            };

            return(GetMessage(TLString.Empty, media));
        }
コード例 #2
0
        private void SendPhoto(Photo p)
        {
            var volumeId = TLLong.Random();
            var localId  = TLInt.Random();
            var secret   = TLLong.Random();

            var fileLocation = new TLFileLocation
            {
                VolumeId = volumeId,
                LocalId  = localId,
                Secret   = secret,
                DCId     = new TLInt(0),    //TODO: remove from here, replace with FileLocationUnavailable
                //Buffer = p.Bytes
            };

            var fileName = String.Format("{0}_{1}_{2}.jpg",
                                         fileLocation.VolumeId,
                                         fileLocation.LocalId,
                                         fileLocation.Secret);

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (var fileStream = store.CreateFile(fileName))
                {
                    fileStream.Write(p.Bytes, 0, p.Bytes.Length);
                }
            }

            var photoSize = new TLPhotoSize
            {
                Type     = TLString.Empty,
                W        = new TLInt(p.Width),
                H        = new TLInt(p.Height),
                Location = fileLocation,
                Size     = new TLInt(p.Bytes.Length)
            };

            var photo = new TLPhoto33
            {
                Id         = new TLLong(0),
                AccessHash = new TLLong(0),
                Date       = TLUtils.DateToUniversalTimeTLInt(MTProtoService.ClientTicksDelta, DateTime.Now),
                Sizes      = new TLVector <TLPhotoSizeBase> {
                    photoSize
                },
            };

            var media = new TLMessageMediaPhoto28 {
                Photo = photo, Caption = TLString.Empty
            };

            var message = GetMessage(TLString.Empty, media);

            if (ImageEditor == null)
            {
                ImageEditor = new ImageEditorViewModel
                {
                    CurrentItem    = message,
                    ContinueAction = ContinueSendPhoto
                };
                NotifyOfPropertyChange(() => ImageEditor);
            }
            else
            {
                ImageEditor.CurrentItem = message;
            }

            BeginOnUIThread(() => ImageEditor.OpenEditor());
        }