Beispiel #1
0
 public Size?GetSize(bool decompressIfNecessary, bool ifDecompressingOccuredLeaveDecompressed = false)
 {
     lock (this._lock)
     {
         if (this._size != null)
         {
             return(this._size);
         }
         else if (this._pngBytes != null)
         {
             Image t = null;
             if (decompressIfNecessary)
             {
                 t          = CompressibleImage.UncompressFromPng(this._pngBytes);
                 this._size = t.Size;
             }
             if (t != null && ifDecompressingOccuredLeaveDecompressed)
             {
                 this._image = t;
             }
             return(this._size);
         }
         else
         {
             return(null);
         }
     }
 }
Beispiel #2
0
        public byte[] GetAsPngBytes(bool canUseImage = true)
        {
            //TODO: not sure why without this lock can be null later
            if (this._lock == null)
            {
                this._lock = new object();
            }

            lock (this._lock)
            {
                if (this._pngBytes != null)
                {
                    return(this._pngBytes);
                }
                else
                {
                    if (canUseImage && this._image != null)
                    {
                        this._pngBytes = CompressibleImage.CompressToPng(this._image);
                        return(this._pngBytes);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
        }
Beispiel #3
0
 public static bool IsNull(this CompressibleImage ci)
 {
     if (ci == null)
     {
         return(true);
     }
     else
     {
         return(ci.IsNull);
     }
 }
Beispiel #4
0
 public void Decompress()
 {
     lock (this._lock)
     {
         if (this._image == null && this._pngBytes != null)
         {
             this._image = CompressibleImage.UncompressFromPng(this._pngBytes);
             this._size  = this._image.Size;
         }
     }
 }
Beispiel #5
0
 public void Compress()
 {
     lock (this._lock)
     {
         if (this._image != null)
         {
             if (this._pngBytes == null)
             {
                 this._pngBytes = CompressibleImage.CompressToPng(this._image);
             }
             this._image.Dispose();
             this._image = null;
         }
     }
 }
Beispiel #6
0
 /// <summary>
 /// IMPORTANT: You must see GetAsAutoDisposableImage() comment first.
 /// </summary>
 /// <returns></returns>
 public Image GetAsImage()
 {
     lock (this._lock)
     {
         if (this._image != null)
         {
             return(this._image);
         }
         else
         {
             if (this._pngBytes != null)
             {
                 Image r = CompressibleImage.UncompressFromPng(this._pngBytes);
                 this._size = r.Size;
                 return(r);
             }
             else
             {
                 return(null);
             }
         }
     }
 }