コード例 #1
0
        private Tuple <MediaObjectRotation, Size> RotateUsingGdi(string filePath, int jpegQuality)
        {
            var actualRotation = GalleryObject.CalculateNeededRotation();

            if (actualRotation <= MediaObjectRotation.Rotate0)
            {
                return(new Tuple <MediaObjectRotation, Size>(actualRotation, Size.Empty));
            }

            // Get reference to the bitmap from which the optimized image will be generated.
            using (var originalBitmap = new System.Drawing.Bitmap(filePath))
            {
                var imgFormat = originalBitmap.RawFormat;                 // Need to grab the format before we rotate or else we lose it (it changes to MemoryBmp)

                try
                {
                    originalBitmap.RotateFlip(GetRotateFlipType());
                }
                catch (System.Runtime.InteropServices.ExternalException)
                {
                    throw new UnsupportedImageTypeException();
                }

                ImageHelper.SaveImageToDisk(originalBitmap, GalleryObject.Original.FileNamePhysicalPath, imgFormat, jpegQuality);

                return(new Tuple <MediaObjectRotation, Size>(actualRotation, new Size(originalBitmap.Width, originalBitmap.Height)));
            }
        }
コード例 #2
0
ファイル: TagGraphicsView.cs プロジェクト: KuroiAme/Indexer
 public TagGraphicsView(GalleryObject go, RectangleF canvas)
 {
     this.go = go;
     Frame = canvas;
     BackgroundColor = UIColor.Clear;
     Opaque = false;
 }
コード例 #3
0
 /// <summary>
 /// Re-extract several metadata values from the file. Call this function when performing an action on a file
 /// that may render existing metadata items inaccurate, such as width and height. The new values are not persisted;
 /// it is expected a subsequent function will do that.
 /// </summary>
 private void RefreshImageMetadata()
 {
     GalleryObject.ExtractMetadata(GalleryObject.MetaDefinitions.Find(MetadataItemName.Width));
     GalleryObject.ExtractMetadata(GalleryObject.MetaDefinitions.Find(MetadataItemName.Height));
     GalleryObject.ExtractMetadata(GalleryObject.MetaDefinitions.Find(MetadataItemName.Dimensions));
     GalleryObject.ExtractMetadata(GalleryObject.MetaDefinitions.Find(MetadataItemName.HorizontalResolution));
     GalleryObject.ExtractMetadata(GalleryObject.MetaDefinitions.Find(MetadataItemName.VerticalResolution));
     GalleryObject.ExtractMetadata(GalleryObject.MetaDefinitions.Find(MetadataItemName.Orientation));
 }
コード例 #4
0
ファイル: TagGraphicsView.cs プロジェクト: KuroiAme/Indexer
 protected override void Dispose(bool disposing)
 {
     color = null;
     color2 = null;
     color3 = null;
     shadow = null;
     go = null;
     base.Dispose (disposing);
 }
コード例 #5
0
        // Sueetie Modified - Bind Checkbox Checked Status

        protected void rptr_OnItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                GalleryObject galleryObject = ((GalleryObject)e.Item.DataItem);
                if (galleryObject.GetType().Name.ToLower() != "album")
                {
                    int      mediaObjectID = galleryObject.Id;
                    CheckBox chkMO         = (CheckBox)e.Item.FindControl("chkMO");
                    chkMO.Checked = SueetieMedia.IsIncludedInDownload(mediaObjectID);
                }
            }
        }
コード例 #6
0
        private Tuple <MediaAssetRotateFlip, Size> RotateFlipUsingWpf(string filePath, int jpegQuality)
        {
            var actualRotation = GalleryObject.CalculateNeededRotation();

            if (actualRotation <= MediaAssetRotateFlip.Rotate0FlipNone)
            {
                return(new Tuple <MediaAssetRotateFlip, Size>(actualRotation, Size.Empty));
            }

            // Grab a reference to the file's metadata properties so we can add them back after the rotation.
            System.Drawing.Imaging.PropertyItem[] propItems = null;
            if (Parent.DisplayType == DisplayObjectType.Original)
            {
                try
                {
                    using (var bmp = new System.Drawing.Bitmap(filePath))
                    {
                        propItems = bmp.PropertyItems;
                    }
                }
                catch (ArgumentException)
                {
                    throw new UnsupportedImageTypeException();
                }
            }

            Tuple <MediaAssetRotateFlip, Size> rotateResult;

            using (var stream = new MemoryStream(File.ReadAllBytes(filePath)))
            {
                var image = GetRotateFlipBitmap(stream, actualRotation);

                var rotatedFlippedImg = BitmapFrame.Create(image);

                var rotatedFlippedBytes = GenerateJpegByteArray(rotatedFlippedImg, jpegQuality);

                File.WriteAllBytes(filePath, rotatedFlippedBytes);

                rotateResult = new Tuple <MediaAssetRotateFlip, Size>(actualRotation, new Size(rotatedFlippedImg.PixelWidth, rotatedFlippedImg.PixelHeight));
            }


            if (rotateResult.Item1 > MediaAssetRotateFlip.Rotate0FlipNone)
            {
                AddMetaValuesBackToRotatedImage(filePath, propItems); // Add meta values back to file
            }

            return(rotateResult);
        }
コード例 #7
0
        private Tuple <MediaAssetRotateFlip, Size> RotateFlipUsingGdi(string filePath, int jpegQuality)
        {
            var actualRotation = GalleryObject.CalculateNeededRotation();

            if (actualRotation <= MediaAssetRotateFlip.Rotate0FlipNone)
            {
                return(new Tuple <MediaAssetRotateFlip, Size>(actualRotation, Size.Empty));
            }

            string tmpImagePath;
            Tuple <MediaAssetRotateFlip, Size> rotateInfo;

            // Get reference to the bitmap from which the optimized image will be generated.
            using (var originalBitmap = new System.Drawing.Bitmap(filePath))
            {
                var imgFormat = originalBitmap.RawFormat; // Need to grab the format before we rotate or else we lose it (it changes to MemoryBmp)

                try
                {
                    originalBitmap.RotateFlip(GetRotateFlipType(actualRotation));
                }
                catch (System.Runtime.InteropServices.ExternalException)
                {
                    throw new UnsupportedImageTypeException();
                }

                // If present, remove the orientation meta property.
                if (Array.IndexOf(originalBitmap.PropertyIdList, ((int)RawMetadataItemName.Orientation)) >= 0)
                {
                    originalBitmap.RemovePropertyItem((int)RawMetadataItemName.Orientation);
                }

                // Save image to temporary location. We can't overwrite the original path because the Bitmap has a lock on it.
                tmpImagePath = Path.Combine(AppSetting.Instance.TempUploadDirectory, String.Concat(Guid.NewGuid().ToString(), ".jpg"));
                ImageHelper.SaveImageToDisk(originalBitmap, tmpImagePath, imgFormat, jpegQuality);

                rotateInfo = new Tuple <MediaAssetRotateFlip, Size>(actualRotation, new Size(originalBitmap.Width, originalBitmap.Height));
            }


            // Now that the original file is freed up, delete it and move the temp file into its place.
            HelperFunctions.MoveFileSafely(tmpImagePath, filePath);

            return(rotateInfo);
        }
コード例 #8
0
        private Tuple<MediaAssetRotateFlip, ISize> RotateFlipImage(string filePath, int jpegQuality)
        {
            var actualRotation = GalleryObject.CalculateNeededRotation();

            if (actualRotation <= MediaAssetRotateFlip.Rotate0FlipNone)
            {
                return new Tuple<MediaAssetRotateFlip, ISize>(actualRotation, Size.Empty);
            }

            string tmpImagePath;
            Tuple<MediaAssetRotateFlip, ISize> rotateInfo;

            using (var image = SixLabors.ImageSharp.Image.Load(filePath))
            {
                image.Mutate(x => x.RotateFlip(GetRotateType(actualRotation), GetFlipType(actualRotation)));

                // Save image to temporary location, then replace the original.
                var fileExtension = Path.GetExtension(filePath);
                tmpImagePath = Path.Combine(AppSetting.Instance.TempUploadDirectory, string.Concat(Guid.NewGuid().ToString(), fileExtension));

                //TODO: Make sure orientation metadata is removed and others are preserved and/or updated (e.g. width/height need updates)
                if (IsJpeg(fileExtension))
                {
                    image.Save(tmpImagePath, new JpegEncoder() { IgnoreMetadata = false, Quality = jpegQuality });
                }
                else
                {
                    image.Save(tmpImagePath); // Encoder is inferred from file extension
                }

                rotateInfo = new Tuple<MediaAssetRotateFlip, ISize>(actualRotation, new Size(image.Width, image.Height));
            }

            // Now that the original file is freed up, delete it and move the temp file into its place.
            if (File.Exists(filePath))
                File.Delete(filePath);

            File.Move(tmpImagePath, filePath);

            return rotateInfo;
        }
コード例 #9
0
        /// <summary>
        /// Check the orientation meta value of the original media object. If the orientation is anything other than
        /// normal (0 degrees), rotate <paramref name="newFilePath" /> to be in the correct orientation. Returns
        /// <see cref="Size.Empty" /> if no rotation is performed.
        /// </summary>
        /// <param name="newFilePath">The full path of the file to rotate.</param>
        /// <param name="jpegQuality">The JPEG quality.</param>
        /// <returns>Returns a <see cref="Size" /> instance containing the width and height of the generated image.</returns>
        protected Size ExecuteAutoRotation(string newFilePath, int jpegQuality)
        {
            // Check for need to rotate and rotate if necessary.
            if (GalleryObject.Rotation != MediaObjectRotation.NotSpecified)
            {
                // When a rotation is explicitly being performed, we don't want to do an auto-rotation.
                return(Size.Empty);
            }

            switch (GalleryObject.GetOrientation())
            {
            case Orientation.Rotated90:
            case Orientation.Rotated180:
            case Orientation.Rotated270:
                var rotateResult = Rotate(newFilePath, jpegQuality);
                return(rotateResult.Item2);

            default:
                return(Size.Empty);
            }
        }
コード例 #10
0
        private Tuple <MediaObjectRotation, Size> RotateUsingWpf(string filePath, int jpegQuality)
        {
            var actualRotation = GalleryObject.CalculateNeededRotation();

            if (actualRotation <= MediaObjectRotation.Rotate0)
            {
                return(new Tuple <MediaObjectRotation, Size>(actualRotation, Size.Empty));
            }

            var bytes = File.ReadAllBytes(filePath);

            using (var stream = new MemoryStream(bytes))
            {
                var image = new TransformedBitmap(ReadBitmapFrame(stream), new RotateTransform(GetRotationInDegrees(actualRotation)));

                var rotatedImg = BitmapFrame.Create(image);

                var rotatedBytes = GenerateJpegByteArray(rotatedImg, jpegQuality);

                File.WriteAllBytes(filePath, rotatedBytes);

                return(new Tuple <MediaObjectRotation, Size>(actualRotation, new Size(rotatedImg.PixelWidth, rotatedImg.PixelHeight)));
            }
        }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExternalThumbnailCreator"/> class.
 /// </summary>
 /// <param name="galleryObject">The gallery object.</param>
 public ExternalThumbnailCreator(GalleryObject galleryObject)
 {
     this._galleryObject = galleryObject;
 }
コード例 #12
0
ファイル: LagerDAO.cs プロジェクト: Skalar/Indexer
 public void DeleteGalleryObject(GalleryObject del)
 {
     conn.Delete (del);
 }
コード例 #13
0
ファイル: LagerDAO.cs プロジェクト: Skalar/Indexer
 void SaveGalleryObjectInner(GalleryObject myObject, GalleryObject item)
 {
     if (item == null) {
         conn.Insert (myObject);
     }
     else {
         conn.Update (myObject);
     }
 }
コード例 #14
0
        private void mySavePicture(UIImage image)
        {
            Console.WriteLine ("mySavePicture()");
            string name = RandomGeneratedName ();
            string[] names = SaveGalleryImage (name, image);
            GalleryObject go = new GalleryObject ();
            go.Name = name;
            go.imageFileName = names [0];
            go.thumbFileName = names [1];

            if (ActiveLocation != null) {
                go.LocationID = ActiveLocation.ID;
                go.LocationType = "Lager";
            }

            if (ActiveContainer != null) {
                go.LocationID = ActiveContainer.ID;
                go.LocationType = "Container";
            }

            items.Add (go);
            AppDelegate.dao.SaveGalleryObject (go);

            carousel.ReloadData ();
        }
コード例 #15
0
ファイル: LagerDAO.cs プロジェクト: KuroiAme/Indexer
        public void SaveGalleryObject(GalleryObject myObject)
        {
            GalleryObject item = this.GetGalleryObjectByID (myObject.ID);

                if(item == null){
                    conn.Insert (myObject);
                }else{
                    conn.Update (myObject);
                }
        }
コード例 #16
0
ファイル: EditTags.cs プロジェクト: Skalar/Indexer
 protected override void Dispose(bool disposing)
 {
     itemtableSource.Dispose ();
     go = null;
     ActivateDetail = null;
     table.Dispose ();
     base.Dispose (disposing);
 }
コード例 #17
0
ファイル: EditTags.cs プロジェクト: Skalar/Indexer
 public EditTags(GalleryObject go )
 {
     this.go = go;
 }
コード例 #18
0
ファイル: LagerDAO.cs プロジェクト: Skalar/Indexer
        public void SaveGalleryObject(GalleryObject myObject)
        {
            GalleryObject item = this.GetGalleryObjectByID (myObject.ID);

            if (limitedSave) {
                IList<GalleryObject> gos = GetAllGalleryObjects ();
                int count = (from g in gos
                            select g).Count();
                if (count > limitedSaves) {
                    RaiseLimitExceeded ();
                } else {
                    SaveGalleryObjectInner (myObject, item);
                }
            } else {
                SaveGalleryObjectInner (myObject, item);
            }
        }