public ActionResult AddEmbroidery(string img, bool allowePublic, string name) { if (User.IsInRole("Admin")) return null; byte[] buffer = Convert.FromBase64String(img.Substring(img.IndexOf(',') + 1)); Bitmap image = null; using (MemoryStream stream = new MemoryStream(buffer)) { Bitmap bitmap2 = new Bitmap(stream); image = new Bitmap(bitmap2.Width, bitmap2.Height); for (int i = 0; i < bitmap2.Height; i++) { for (int j = 0; j < bitmap2.Width; j++) { image.SetPixel(j, i, bitmap2.GetPixel(j, i)); } } } IKernel root = new StandardKernel(new INinjectModule[] { new DataModelCreator() }); IRepository<Embroidery> repository = root.Get<IRepository<Embroidery>>(new IParameter[0]); Size newSize = this.GetNewSize(image, 150); Embroidery item = new Embroidery(image, newSize) { Name = name, UserId = WebSecurity.CurrentUserId, DateCreated = DateTime.Now, PublicEmbroidery = allowePublic }; repository.Add(item); return base.RedirectToAction("Index", "Gallery"); }
public void CreateEmbroidery(Preview preview, string imageName, int coefficient, int cellsCount, DColor[] palette, char[] symbols, DColor symbolColor, Embroidery.GridType gridType) { BitmapSource bitmapSource = null; try { DBitmap _imageFromFile = new DBitmap(imageName); Func<DBitmap, DBitmap> getCopyBitmap = new Func<DBitmap, DBitmap>(GetCopyOfBitmap); IAsyncResult getCopyBitmapResult = getCopyBitmap.BeginInvoke(_imageFromFile, null, null); DBitmap inputImage = getCopyBitmap.EndInvoke(getCopyBitmapResult); Embroidery.EmbroideryCreatorServiceClient wcf_service = new Embroidery.EmbroideryCreatorServiceClient(); Func<DBitmap, int, int, DColor[], char[], DColor, Embroidery.GridType, DBitmap> getEmbroidery = new Func<DBitmap, int, int, DColor[], char[], DColor, Embroidery.GridType, DBitmap>(wcf_service.GetEmbroidery); IAsyncResult getEmbroideryResult = getEmbroidery.BeginInvoke(inputImage, coefficient, cellsCount, palette, symbols, DColor.Black, gridType, null, null); DBitmap resultImage = getEmbroidery.EndInvoke(getEmbroideryResult); if (resultImage == null) { MessageBox.Show("Some error occured on the server"); //HideLoading(); return; } bitmapSource = GetBitmapSource(resultImage); } catch (OutOfMemoryException ex) { MessageBox.Show("Sorry, but image is too large :("); //HideLoading(); return; } catch (Exception ex) { MessageBox.Show("Some exception was occured. Message: " + ex.Message); //HideLoading(); return; } bitmapSource.Freeze(); preview.Dispatcher.BeginInvoke(new Action(() => { preview.loadingPanel.Visibility = System.Windows.Visibility.Collapsed; preview.previewImage.Source = bitmapSource; }), System.Windows.Threading.DispatcherPriority.Normal); }