Ejemplo n.º 1
0
 private void gridMain_CellClick(object sender, ODGridClickEventArgs e)
 {
     //Determine if it's a folder or a file that was clicked
     //If a folder, do nothing
     //If a file, download a thumbnail and display it
     if (gridMain.Rows[gridMain.GetSelectedIndex()].Cells[0].Text.Contains("."))             //They selected a file because there is an extension.
     //Place thumbnail within odPictureox to display
     {
         OpenDentalCloud.Core.TaskStateThumbnail state = CloudStorage.GetThumbnail(textPath.Text, gridMain.Rows[gridMain.GetSelectedIndex()].Cells[0].Text);
         if (state == null || state.FileContent == null || state.FileContent.Length < 2)
         {
             labelThumbnail.Visible = true;
             odPictureBox.Visible   = false;
         }
         else
         {
             labelThumbnail.Visible = false;
             odPictureBox.Visible   = true;
             using (MemoryStream stream = new MemoryStream(state.FileContent)) {
                 _thumbnail = new Bitmap(Image.FromStream(stream));
             }
             odPictureBox.Image = _thumbnail;
             odPictureBox.Invalidate();
         }
     }
     else
     {
         labelThumbnail.Visible = false;
         odPictureBox.Visible   = false;
     }
 }
Ejemplo n.º 2
0
        ///<summary>Gets the full sized image, with settings applied from doc.  Throws exceptions.</summary>
        public static Bitmap GetFullImage(Document doc, string patientFolder)
        {
            //No need to check RemotingRole; no call to db.
            string shortFileName = doc.FileName;

            //If no file name associated with the document, then there cannot be a thumbnail,
            //because thumbnails have the same name as the original image document.
            if (shortFileName.Length < 1)
            {
                throw new ODException("No image file associated with document.");
            }
            string fullName = ODFileUtils.CombinePaths(patientFolder, shortFileName);

            //If the document no longer exists, then there is no corresponding thumbnail image.
            if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ && !File.Exists(fullName))
            {
                throw new ODException("No image file found for document.");
            }
            //If the specified document is not an image return 'not available'.
            if (!ImageHelper.HasImageExtension(fullName))
            {
                throw new ODException("Document is not associated to an image file format.");
            }
            Bitmap sourceImage = null;

            if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ)
            {
                sourceImage = new Bitmap(fullName);
            }
            else              //Cloud
            {
                OpenDentalCloud.Core.TaskStateThumbnail state = CloudStorage.GetThumbnail(patientFolder, shortFileName);
                if (state.FileContent != null)
                {
                    using (MemoryStream stream = new MemoryStream(state.FileContent)) {
                        sourceImage = new Bitmap(Image.FromStream(stream));
                    }
                }
                else
                {
                    sourceImage = new Bitmap(1, 1);
                }
            }
            Bitmap fullImage = ImageHelper.ApplyDocumentSettingsToImage(doc, sourceImage, ImageSettingFlags.ALL);

            sourceImage.Dispose();
            return(fullImage);
        }
Ejemplo n.º 3
0
 ///<summary>Returns null if the the image could not be downloaded. Sychronous.</summary>
 public static Bitmap GetThumbnail(string imagePath, int size = 128)
 {
     if (CloudStorage.IsCloudStorage)
     {
         OpenDentalCloud.Core.TaskStateThumbnail state = CloudStorage.GetThumbnail(Path.GetDirectoryName(imagePath), Path.GetFileName(imagePath));
         if (state == null || state.FileContent == null || state.FileContent.Length < 2)
         {
             return(null);
         }
         using (MemoryStream stream = new MemoryStream(state.FileContent)) {
             return(ImageHelper.GetThumbnail(Image.FromStream(stream), size));
         }
     }
     //Not cloud
     return(ImageHelper.GetThumbnail(Image.FromFile(imagePath), size));
 }
Ejemplo n.º 4
0
        ///<summary>Gets the corresponding thumbnail image for the given document object. The document is expected to be an image, and a 'not available' image is returned if the document is not an image. The thumbnail for every document is in a folder named 'thumbnails' within the same directly level.</summary>
        public static Bitmap GetThumbnail(Document doc, string patFolder, int size)
        {
            //No need to check RemotingRole; no call to db.
            string shortFileName = doc.FileName;

            //If no file name associated with the document, then there cannot be a thumbnail,
            //because thumbnails have the same name as the original image document.
            if (shortFileName.Length < 1)
            {
                return(NoAvailablePhoto(size));
            }
            string fullName = ODFileUtils.CombinePaths(patFolder, shortFileName);

            //If the document no longer exists, then there is no corresponding thumbnail image.
            if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ && !File.Exists(fullName))
            {
                return(NoAvailablePhoto(size));
            }
            //If the specified document is not an image return 'not available'.
            if (!ImageHelper.HasImageExtension(fullName))
            {
                return(NoAvailablePhoto(size));
            }
            //Create Thumbnails folder if it does not already exist for this patient folder.
            string thumbPath = ODFileUtils.CombinePaths(patFolder, "Thumbnails");

            if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ && !Directory.Exists(thumbPath))
            {
                try {
                    Directory.CreateDirectory(thumbPath);
                }
                catch {
                    throw new ApplicationException(Lans.g("Documents", "Error: Could not create 'Thumbnails' folder for patient: ") + thumbPath);
                }
            }
            string thumbFileExt      = Path.GetExtension(shortFileName);
            string thumbCoreFileName = shortFileName.Substring(0, shortFileName.Length - thumbFileExt.Length);
            string thumbFileName     = ODFileUtils.CombinePaths(new string[] { patFolder, "Thumbnails",
                                                                               thumbCoreFileName + "_" + size + thumbFileExt });

            //Use the existing thumbnail if it already exists and it was created after the last document modification.
            if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ && File.Exists(thumbFileName))
            {
                try {
                    DateTime thumbModifiedTime = File.GetLastWriteTime(thumbFileName);
                    if (thumbModifiedTime > doc.DateTStamp)
                    {
                        return((Bitmap)Bitmap.FromFile(thumbFileName));
                    }
                }
                catch (Exception) {
                    try {
                        File.Delete(thumbFileName);                         //File may be invalid, corrupted, or unavailable. This was a bug in previous versions.
                    }catch (Exception) {
                        //we tried our best, and it just wasn't good enough
                    }
                }
            }
            //Add thumbnail
            Bitmap thumbBitmap;
            //Gets the cropped/flipped/rotated image with any color filtering applied.
            Bitmap sourceImage = null;

            try {
                if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ)
                {
                    sourceImage = new Bitmap(fullName);
                }
                else                  //Cloud
                {
                    OpenDentalCloud.Core.TaskStateThumbnail state = CloudStorage.GetThumbnail(patFolder, shortFileName);
                    if (state.FileContent != null)
                    {
                        using (MemoryStream stream = new MemoryStream(state.FileContent)) {
                            sourceImage = new Bitmap(Image.FromStream(stream));
                        }
                    }
                    else
                    {
                        sourceImage = new Bitmap(1, 1);
                    }
                }
            }
            catch {
                return(NoAvailablePhoto(size));
            }
            Bitmap fullImage = ImageHelper.ApplyDocumentSettingsToImage(doc, sourceImage, ImageSettingFlags.ALL);

            sourceImage.Dispose();
            thumbBitmap = ImageHelper.GetThumbnail(fullImage, size);
            fullImage.Dispose();
            if (PrefC.AtoZfolderUsed == DataStorageType.LocalAtoZ)           //Only save thumbnail to local directory if using local AtoZ
            {
                try {
                    thumbBitmap.Save(thumbFileName);
                }
                catch {
                    //Oh well, we can regenerate it next time if we have to!
                }
            }
            return(thumbBitmap);
        }