Beispiel #1
0
        public override PureImage FromStream(Stream stream)
        {
            WindowsFormsImage ret = null;

            try
            {
#if !PocketPC
                Image m = Image.FromStream(stream, true, Win7OrLater ? false : true);
#else
                Image m = new Bitmap(stream);
#endif
                if (m != null)
                {
                    ret = new WindowsFormsImage();
#if !PocketPC
                    ret.Img = ColorMatrix != null?ApplyColorMatrix(m, ColorMatrix) : m;
#else
                    ret.Img = m;
#endif
                }
            }
            catch
            {
                ret = null;
            }

            return(ret);
        }
Beispiel #2
0
        public override bool Save(Stream stream, GMap.NET.PureImage image)
        {
            WindowsFormsImage ret = image as WindowsFormsImage;
            bool ok = true;

            if (ret.Img != null)
            {
                // try png
                try
                {
                    ret.Img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                }
                catch
                {
                    // try jpeg
                    try
                    {
                        stream.Seek(0, SeekOrigin.Begin);
                        ret.Img.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    }
                    catch
                    {
                        ok = false;
                    }
                }
            }
            else
            {
                ok = false;
            }

            return(ok);
        }
Beispiel #3
0
        public override PureImage FromStream(Stream stream)
        {
            WindowsFormsImage ret = null;
             try
             {
            #if !PocketPC
            Image m = Image.FromStream(stream, true, Win7OrLater ? false : true);
            #else
            Image m = new Bitmap(stream);
            #endif
            if(m != null)
            {
               ret = new WindowsFormsImage();
            #if !PocketPC
               ret.Img = ColorMatrix != null ? ApplyColorMatrix(m, ColorMatrix) : m;
            #else
               ret.Img = m;
            #endif
            }

             }
             catch(Exception ex)
             {
            ret = null;
            Debug.WriteLine("FromStream: " + ex.ToString());
             }

             return ret;
        }
Beispiel #4
0
 public PureImage GetImageFromCache(MapType type, Point pos, int zoom)
 {
     try
     {
         string fileName = GetFilename(type, pos, zoom, false);
         FileInfo fi = new FileInfo(fileName);
         if (fi.Exists && fi.LastWriteTimeUtc > _CacheDate)
         {
             Image image = Image.FromFile(fileName);
             WindowsFormsImage img = new WindowsFormsImage();
             img.Img = image;
             img.Data = new MemoryStream();
             image.Save(img.Data, System.Drawing.Imaging.ImageFormat.Jpeg);
             System.Diagnostics.Debug.WriteLine(string.Format("{0} FilePureImageCache.GetImageFromCache(type={1}, pos={2}, zoom={3}, file date={4}) succeeded.", DateTime.Now, type, pos, zoom, fi.LastWriteTimeUtc));
             return img;
         }
         else
         {
             System.Diagnostics.Debug.WriteLine(string.Format("{0} FilePureImageCache.GetImageFromCache(type={1}, pos={2}, zoom={3}) NOT IN CACHE.", DateTime.Now, type, pos, zoom));
             return null;
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Error in FilePureImageCache.GetImageFromCache:\r\n" + ex.ToString());
         return null;
     }
 }
Beispiel #5
0
        public override PureImage FromStream(Stream stream)
        {
            WindowsFormsImage ret = null;

            try
            {
#if !PocketPC
                Image m = Image.FromStream(stream, true, VistaOrLater ? false : true);
#else
                Image m = new Bitmap(stream);
#endif
                if (m != null)
                {
                    ret = new WindowsFormsImage();
#if !PocketPC
                    ret.Img = ColorMatrix != null?ApplyColorMatrix(m, ColorMatrix) : m;
#else
                    ret.Img = m;
#endif
                }
            }
            catch (Exception ex)
            {
                ret = null;
                Debug.WriteLine("FromStream: " + ex.ToString());
            }

            return(ret);
        }
Beispiel #6
0
        public override PureImage FromStream(Stream stream)
        {
            WindowsFormsImage ret = null;

            try
            {
                if (!GMaps.Instance.IsRunningOnMono)
                {
                    Image m = Image.FromStream(stream, true, true);
                    if (m != null)
                    {
                        ret     = new WindowsFormsImage();
                        ret.Img = m;
                    }
                }
                else // mono yet do not support validation
                {
                    Image m = Image.FromStream(stream);
                    if (m != null)
                    {
                        ret     = new WindowsFormsImage();
                        ret.Img = m;
                    }
                }
            }
            catch (Exception ex)
            {
                ret = null;
                Debug.WriteLine("FromStream: " + ex.ToString());
            }
            finally
            {
                try
                {
                    stream.Seek(0, System.IO.SeekOrigin.Begin);

                    if (ret == null)
                    {
                        stream.Dispose();
                    }
                }
                catch
                {
                }
            }
            return(ret);
        }
Beispiel #7
0
        public override PureImage FromStream(Stream stream)
        {
            WindowsFormsImage ret = null;
            try
            {
                if (!GMaps.Instance.IsRunningOnMono)
                {
                    Image m = Image.FromStream(stream, true, true);
                    if (m != null)
                    {
                        ret = new WindowsFormsImage();
                        ret.Img = m;
                    }
                }
                else // mono yet do not support validation
                {
                    Image m = Image.FromStream(stream);
                    if (m != null)
                    {
                        ret = new WindowsFormsImage();
                        ret.Img = m;
                    }
                }
            }
            catch (Exception ex)
            {
                ret = null;
                Debug.WriteLine("FromStream: " + ex.ToString());
            }
            finally
            {
                try
                {
                    stream.Seek(0, System.IO.SeekOrigin.Begin);

                    if (ret == null)
                    {
                        stream.Dispose();
                    }
                }
                catch
                {
                }
            }
            return ret;
        }
Beispiel #8
0
        public override PureImage FromStream(Stream stream)
        {
            WindowsFormsImage ret = null;

            try
            {
                if (!GMaps.Instance.IsRunningOnMono)
                {
#if !PocketPC
                    Image m = Image.FromStream(stream, true, true);
#else
                    Image m = new Bitmap(stream);
#endif
                    if (m != null)
                    {
                        ret = new WindowsFormsImage();
#if !PocketPC
                        ret.Img = ColorMatrix != null?ApplyColorMatrix(m, ColorMatrix) : m;
#else
                        ret.Img = m;
#endif
                    }
                }
                else // mono yet do not support validation
                {
#if !PocketPC
                    Image m = Image.FromStream(stream);
#else
                    Image m = new Bitmap(stream);
#endif
                    if (m != null)
                    {
                        ret = new WindowsFormsImage();
#if !PocketPC
                        ret.Img = ColorMatrix != null?ApplyColorMatrix(m, ColorMatrix) : m;
#else
                        ret.Img = m;
#endif
                    }
                }
            }
            catch (Exception ex)
            {
                ret = null;
                Debug.WriteLine("FromStream: " + ex.ToString());
            }
            finally
            {
                try
                {
                    stream.Seek(0, System.IO.SeekOrigin.Begin);

                    if (ret == null)
                    {
#if !PocketPC
                        stream.Dispose();
#else
                        IDisposable s = stream as IDisposable;
                        if (s != null)
                        {
                            s.Dispose();
                        }
#endif
                    }
                }
                catch
                {
                }
            }
            return(ret);
        }
Beispiel #9
0
        public override PureImage FromStream(Stream stream)
        {
            WindowsFormsImage ret = null;
             try
             {
            if(!GMaps.Instance.IsRunningOnMono)
            {
            #if !PocketPC
               Image m = Image.FromStream(stream, true, true);
            #else
               Image m = new Bitmap(stream);
            #endif
               if(m != null)
               {
                  ret = new WindowsFormsImage();
            #if !PocketPC
                  ret.Img = ColorMatrix != null ? ApplyColorMatrix(m, ColorMatrix) : m;
            #else
                  ret.Img = m;
            #endif
               }
            }
            else // mono yet do not support validation
            {
            #if !PocketPC
               Image m = Image.FromStream(stream);
            #else
               Image m = new Bitmap(stream);
            #endif
               if(m != null)
               {
                  ret = new WindowsFormsImage();
            #if !PocketPC
                  ret.Img = ColorMatrix != null ? ApplyColorMatrix(m, ColorMatrix) : m;
            #else
                  ret.Img = m;
            #endif
               }
            }
             }
             catch(Exception ex)
             {
            ret = null;
            Debug.WriteLine("FromStream: " + ex.ToString());
             }
             finally
             {
            try
            {
               stream.Seek(0, System.IO.SeekOrigin.Begin);

               if(ret == null)
               {
            #if !PocketPC
                  stream.Dispose();
            #else
                  IDisposable s = stream as IDisposable;
                  if(s != null)
                  {
                     s.Dispose();
                  }
            #endif
               }
            }
            catch
            {
            }
             }
             return ret;
        }