Exemplo n.º 1
0
        private Uri StoreImage(File file)
        {
            try
            {
                ContentValues e = new ContentValues();
                e.Put("title", file.Name);
                e.Put("mime_type", "image/jpeg");
                e.Put("description", "mixi Photo");
                e.Put("orientation", ExifInterfaceCompat.GetExifOrientation(file.AbsolutePath));
                long date = ExifInterfaceCompat.GetExifDateTimeInMillis(file.AbsolutePath);
                if (date != -1L)
                {
                    e.Put("datetaken", date);
                }

                Uri imageUri = this.mContext.ContentResolver.Insert(Media.ExternalContentUri, e);
                using (System.IO.FileStream fos = (System.IO.FileStream) this.mContext.ContentResolver.OpenOutputStream(imageUri))
                {
                    using (System.IO.FileStream fis = new System.IO.FileStream(file.AbsolutePath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                    {
                        CopyFile(fos, fis);
                    }
                }
                this.GenerateThumbnails(ContentUris.ParseId(imageUri));
                return(imageUri);
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        private Uri FindPhotoFromRecentlyTaken(File file)
        {
            if (this.mRecentlyUpdatedPhotos == null)
            {
                this.UpdateLatestPhotos();
            }
            long fileSize = file.Length();
            long taken    = ExifInterfaceCompat.GetExifDateTimeInMillis(file.AbsolutePath);
            int  maxPoint = 0;

            MediaStoreCompat.PhotoContent maxItem = null;

            foreach (var item in this.mRecentlyUpdatedPhotos)
            {
                int point = 0;
                if ((long)item.size == fileSize)
                {
                    ++point;
                }
                if (item.taken == taken)
                {
                    ++point;
                }
                if (point > maxPoint)
                {
                    maxPoint = point;
                    maxItem  = item;
                }
            }

            if (maxItem != null)
            {
                this.GenerateThumbnails(maxItem.id);
                return(ContentUris.WithAppendedId(Media.ExternalContentUri, maxItem.id));
            }
            else
            {
                return(null);
            }
        }