예제 #1
0
        public static bool ImageImport(this DeviceModel deviceModel, Stream ImageStream)
        {
            try
            {
                using (Bitmap inputBitmap = new Bitmap(ImageStream))
                {
                    using (Image outputBitmap = inputBitmap.ResizeImage(256, 256))
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            outputBitmap.SavePng(ms);
                            ms.Position = 0;

                            var deviceModelImagePath = deviceModel.ImageFilePath();


                            using (var storeStream = new FileStream(deviceModelImagePath, FileMode.Create, FileAccess.Write, FileShare.None))
                            {
                                ms.CopyTo(storeStream);
                            }
                            //deviceModel.Image = ms.ToArray();
                        }
                    }
                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
예제 #2
0
        public void TestResizeImageToMaximumDimension()
        {
            using (var image = new Bitmap(ImageLocation))
            {
                var resizedImage = image.ResizeImage(90);

                Assert.AreEqual(90, resizedImage.Width);

                resizedImage.Dispose();
            }
        }
예제 #3
0
        public void TestResizeImage()
        {
            using (var image = new Bitmap(ImageLocation))
            {
                var resizedImage = image.ResizeImage(320, 200);

                Assert.AreEqual(320, resizedImage.Width);
                Assert.AreEqual(200, resizedImage.Height);

                resizedImage.Dispose();
            }
        }
예제 #4
0
 public static byte[] ResizeImage(this byte[] imageBytes, int width, int height)
 {
     try
     {
         using (MemoryStream streamInput = new MemoryStream(imageBytes))
         {
             System.Drawing.Image image = new Bitmap(streamInput);
             ImageFormat oldFormat = image.RawFormat;
             image = image.ResizeImage(width, height);
             byte[] result = image.GetBytes(oldFormat);
             return result;
         }
     }
     catch (Exception ex)
     {
         return imageBytes;
     }
 }
예제 #5
0
 public ActionResult Image(string imageFile, int? width, int? height, int? id)
 {
     var memoryStream = new MemoryStream();
     var image = new Bitmap(ObjectsRepository.CatalogFolder + imageFile.Replace("___", "/"));
     if (width != null && height != null)
     {
         image = image.Clip10X15();
         image = image.ResizeImage(width.Value, height.Value);
     }
     if (id != null)
     {
         image = image.AddBluredRect(30);
         var htmlText = ObjectsRepository.GetObjectDescription(id.Value);
         if (!string.IsNullOrEmpty(htmlText))
         {
             image = image.AddText(30, 0, htmlText);
         }
         //var backImage = new Bitmap(Server.MapPath("~\\Content\\images\\keyend.png"));
         //image = image.AddBackBitmap(backImage);
     }
     image.Save(memoryStream, ImageFormat.Jpeg);
     memoryStream.Seek(0, SeekOrigin.Begin);
     return File(memoryStream, "image/jpeg");
 }
예제 #6
0
        void PasteScaledBitmapImageToTileByLatLon(int zoom, double Lon, double Lat, int xTile, int yTile, double scale, Bitmap iconImage)
        {
            int width = iconImage.Width;
            int height = iconImage.Height;
            if (scale != 1.0)
            {
                width = (int)(width * scale);
                height = (int)(height * scale);

            }
            CopyRegionIntoImage(iconImage.ResizeImage((width), (height )), new Rectangle(0, 0, width, height), GetTargetBound(zoom, Lon, Lat, xTile, yTile, width, height));
        }
예제 #7
0
        void PasteIcon(Bitmap icon, int x, int y, double scale)
        {
            int width = icon.Width;
            int height = icon.Height;
            if (scale != 1.0)
            {
                icon.ResizeImage((int)(width * scale), (int)(height * scale));
                width = (int)(width * scale);
                height = (int)(height * scale);
            }

            CopyRegionIntoImage(icon, new Rectangle(0, 0, width, height),  new Rectangle(x, y, width, width));
        }
예제 #8
0
        /// <summary>
        /// Load all external mugshots into the cache.
        /// </summary>
        private static void LoadExternalMugshots()
        {
            string mugshotFolder = Path.Combine(CIX.HomeFolder, "Mugshots");
            if (Directory.Exists(mugshotFolder))
            {
                string[] allFiles = Directory.GetFiles(mugshotFolder);
                foreach (string filename in allFiles)
                {
                    try
                    {
                        string username = Path.GetFileNameWithoutExtension(filename);
                        Image mugshotImage = new Bitmap(filename);
                        mugshotImage = mugshotImage.ResizeImage(MaxMugshotWidth, MaxMugshotHeight);

                        if (username != null && mugshotImage != null)
                        {
                            Mugshot mugshot = new Mugshot();

                            ImageConverter converter = new ImageConverter();
                            mugshot.Image = (byte[])converter.ConvertTo(mugshotImage, typeof(byte[]));
                            mugshot.Username = username;

                            Cache[username] = mugshot;
                        }
                    }
                    catch (Exception e)
                    {
                        LogFile.WriteLine("Error loading {0} : {1}", filename, e.Message);
                    }
                }
            }
        }