private void ValidateAndLoadImage(string file) { if (string.IsNullOrEmpty(file)) { return; } // Validate the file try { sourceImage = new Bitmap(file); } catch (System.ArgumentException ex) { throw new Galatea.TeaArgumentException("Invalid image type.", ex); } // Display in the User Control SetDisplayImage(sourceImage); // Stream Bitmap to Recognition Manager ImagingContextStream stream = ImagingContextStream.FromImage(displayImage); Program.Engine.ExecutiveFunctions.StreamContext(this, Program.Engine.Vision.ImageAnalyzer, ContextType.Machine, InputType.Visual, stream, typeof(Bitmap)); // Get Blob blobImage = Program.Engine.Vision.ImageAnalyzer.ContextBlobImage; }
private void Map_OnMouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { selectionStarted = true; renderer.StartSelection(new Point(e.X, e.Y)); } else { BlobImage img = selectedTile(); if (img == null) { return; } CellData.FloorData floor = new CellData.FloorData(); floor.Image = img; renderer.SetFloorAt(floor, e.X, e.Y); } if (MouseDown != null) { MouseDown(e); } }
public async Task <long> CreateBlobImageAsync(long tenantId, BlobImage blob) { using (SqlConnection connection = new SqlConnection(_options.Value.SqlConnectionString)) { connection.Open(); long blobId = await connection.QuerySingleAsync <long>(@" DECLARE @BlobId bigint INSERT INTO cms.Upload (TenantId, UploadType, Name, Size, Committed, Created, Updated) VALUES (@TenantId, @BlobType, @Name, @Size, 0, @Created, @Updated) SET @BlobId = (SELECT CAST(SCOPE_IDENTITY() as bigint)) INSERT INTO cms.[Image] (TenantId, UploadId, Width, Height) VALUES (@TenantId, @BlobId, @Width, @Height) SELECT @BlobId ", new { TenantId = tenantId, blob.BlobType, blob.Name, blob.Size, blob.Created, blob.Updated, blob.Width, blob.Height } ); return(blobId); } }
private Blob GetBlobFromDto(BlobDto dto) { Blob blob = null; if (dto == null) { return(blob); } if (dto.BlobType == BlobType.Image) { blob = new BlobImage { Width = dto.Width.Value, Height = dto.Height.Value, BlobType = BlobType.Image } } ; else { blob = new Blob { BlobType = BlobType.Document } }; List <string> pathSegments = GetPathSegmentsFromFolders(dto.Folder1, dto.Folder2, dto.Folder3); blob.TenantId = dto.TenantId; blob.BlobId = dto.BlobId; blob.Size = dto.Size; blob.ContentType = dto.ContentType; blob.Path = GetPathFromPathSegments(pathSegments); blob.Name = dto.Name; blob.Created = dto.Created; blob.Updated = dto.Updated; return(blob); }
public async Task <IActionResult> OnPost() { Product existingProduct = await _invManager.GetProductByID(ID.GetValueOrDefault()) ?? new Product(); if (Image != null) { var filePath = Path.GetTempFileName(); using (var stream = new FileStream(filePath, FileMode.Create)) { await Image.CopyToAsync(stream); } var container = await BlobImage.GetContainer("products"); BlobImage.UploadFile(container, Image.FileName, filePath); CloudBlob blob = await BlobImage.GetBlob(Image.FileName, container.Name); Product.ImgUrl = blob.Uri.ToString(); existingProduct.ImgUrl = Product.ImgUrl; } existingProduct.Name = Product.Name; existingProduct.Price = Product.Price; existingProduct.ReleaseDate = Product.ReleaseDate; existingProduct.SKU = Product.SKU; existingProduct.Generation = Product.Generation; existingProduct.Description = Product.Description; await _invManager.UpdateProduct(ID.GetValueOrDefault(), existingProduct); return(RedirectToPage("/Admin/Products/Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Product = await _productManager.GetProductByID((int)id); var container = await BlobImage.GetContainer("product-image-asset-blob"); string[] imageURIArray = Product.Image.Split("/"); string imageName = imageURIArray[imageURIArray.Length - 1]; CloudBlob image = await BlobImage.GetBlob(imageName, container.Name); if (image != null) { await image.DeleteAsync(); } if (Product != null) { await _productManager.DeleteProduct(Product); } return(RedirectToPage("./Index")); }
private HtmlPreviewImage GetHtmlPreviewImageFromHtmlBlob(HtmlBlobSet blobSet, IDictionary <long, BlobImage> blobsById) { BlobImage blobImage = blobsById[blobSet.PreviewImageBlobId]; return(new HtmlPreviewImage { BlobSetId = blobSet.BlobSetId, Width = blobImage.Width, Height = blobImage.Height, Name = blobImage.Name }); }
public async Task <IElementView <PageHeaderElementSettings, PageHeaderElementContent> > ReadElementViewAsync(long tenantId, long elementId, IPageContext context) { PageHeaderElementSettings settings = await _elementRepository.ReadElementSettingsAsync(tenantId, elementId); if (settings == null) { return(null); } Page page = await _pageService.ReadPageAsync(tenantId, context.PageId); PageHeaderElementContent content = new PageHeaderElementContent(); content.Created = settings.ShowCreated ? (DateTime?)page.Created : null; content.Updated = settings.ShowUpdated && !(settings.ShowCreated && (page.Created.Date == page.Updated.Date)) ? (DateTime?)page.Updated : null; content.Occurred = settings.ShowOccurred && page.Occurred.HasValue ? page.Occurred : null; content.OccursInFuture = content.Occurred.HasValue && (page.Occurred.Value.Date > DateTime.UtcNow.Date); content.Name = settings.ShowName ? page.Name : null; content.Description = settings.ShowDescription ? page.Description : null; if (settings.ShowImage && page.ThumbnailImageBlobId.HasValue) { BlobImage thumbnailImage = (BlobImage)await _storageService.ReadBlobAsync(tenantId, page.ThumbnailImageBlobId.Value); content.Image = new PageHeaderImage { BlobId = thumbnailImage.BlobId, PageId = page.PageId, Height = thumbnailImage.Height, Width = thumbnailImage.Width }; } if (settings.ShowBreadcrumbs) { IEnumerable <Page> pages = await _pageService.ListPagesInHierarchyAsync(tenantId, context.PageId); content.Breadcrumbs = pages.Reverse().Select(p => new PageHeaderBreadcrumb { Home = p.ParentPageId == null, Name = p.Name, PageId = p.PageId, PageName = p.Name }); } return(new ElementView <PageHeaderElementSettings, PageHeaderElementContent> { Settings = settings, Content = content }); }
private LatestThreadsImage GetImage(long?blobId, IDictionary <long, BlobImage> blobsById) { if (!blobId.HasValue) { return(null); } BlobImage blobImage = blobsById[blobId.Value]; return(new LatestThreadsImage { BlobId = blobImage.BlobId, Height = blobImage.Height, Width = blobImage.Width }); }
public static List <BlobImage> GetBlobsFrom(FileInfo[] files) { List <BlobImage> result = new List <BlobImage>(files.Length); foreach (FileInfo file in files) { BlobFile blob = new BlobFile(); using (Stream s = file.Open(FileMode.Open, FileAccess.Read)) { blob.Deserialize(s); foreach (var entry in blob.Entries) { BlobImage image = new BlobImage(); image.BlobReference = new BlobReference(); image.BlobReference.Id = entry.Name; image.BlobReference.FileName = file.Name; s.Seek(entry.Offset, SeekOrigin.Begin); byte[] data = new byte[entry.Size]; s.Read(data, 0, data.Length); Bitmap b = null; try { b = GenerateBitmapFromCfs(new MemoryStream(data), file.Name); } catch (Exception) { b = null; } if (b == null) { continue; } image.Image = b; result.Add(image); } } } return(result); }
private PageListImage GetImage(Page page, IDictionary <long, BlobImage> imagesById) { if (!page.ThumbnailImageBlobId.HasValue) { return(null); } BlobImage thumbnailImage = imagesById[page.ThumbnailImageBlobId.Value]; return(new PageListImage { BlobId = thumbnailImage.BlobId, PageId = page.PageId, Width = thumbnailImage.Width, Height = thumbnailImage.Height }); }
private void ExecutiveFunctions_ContextRecognition(object sender, ContextRecognitionEventArgs e) { Bitmap bitmap; BlobImage blobImage = Program.Engine.Vision.ImageAnalyzer.ContextBlobImage; Color fillColor = Color.FromArgb(255, blobImage.MeanColor); Color backgroundColor = Color.FromArgb(232, 232, 232); // Cheat a little bit if (!StaticMode) { Accord.Imaging.HSL hsl = new Accord.Imaging.HSL((int)fillColor.GetHue(), fillColor.GetSaturation(), fillColor.GetBrightness()); hsl.NormalizeSaturation(); fillColor = hsl.ToRGB().Color; } if (e.TemplateType != TemplateType.Shape || !(e.NamedTemplate is ShapeTemplate)) { bitmap = GuiImaging.GetBitmapBlobImage(blobImage.BitmapBlob, fillColor, backgroundColor); ImageDump(bitmap, "Color"); } else { ShapeTemplate st = e.NamedTemplate as ShapeTemplate; Color pointColor = Color.FromArgb(64, Color.Cyan); Color firstPointColor = Color.FromArgb(64, Color.Red); Color lastPointColor = Color.FromArgb(64, Color.Blue); bitmap = GuiImaging.GetBitmapBlobImage(st.BitmapBlob, fillColor, backgroundColor); if (st.BlobPoints != null) { // Get Initial Points GuiPointsGraphics.DrawInitialPoints(pointColor, firstPointColor, lastPointColor, GuiPointShape.Cross, st.BlobPoints.InitialPoints, bitmap); // Get final Blob Points GuiPointsGraphics.DrawBlobPoints(bitmap, st.BlobPoints, Color.Magenta, Color.Red, Color.Blue, Color.Green, Color.Yellow); } ImageDump(bitmap, "Shape"); } // Update Display FillDisplayImage(blobImage, bitmap); }
public HttpResponseMessage detail(int id) { var uploadactivity = _IWkflowinstanceService.GetWkflowinstance(id); var result = PlatformMappingHelper.Map <WkflowInstance, BatchProcessingWorkflowDTO>(uploadactivity); var storageAccess = _IPortsettingService.GetPortsettings().Where(p => p.PortId == 1 && p.Setting.Name == "StorageAccess").FirstOrDefault().PortSettingValues.FirstOrDefault().Value; var storageContainer = uploadactivity.WkflowInstanceDocs.FirstOrDefault().Doc.soStorageContainer; var versionData = new VersionData(); versionData.container = storageContainer; versionData.accountKey = storageAccess; int imageType = 0; try { if (result.FileName.ToUpper().Contains(".PDF")) { imageType = 1; var pdfimage = BlobImage.GetImage(uploadactivity.WkflowInstanceDocs.FirstOrDefault().Doc.soStorageKey, versionData, imageType); result.image = pdfimage[0]; } else { imageType = 2; result.preview = BlobImage.GetImage(uploadactivity.WkflowInstanceDocs.FirstOrDefault().Doc.soStorageKey, versionData, imageType); } } catch (Exception e) { } if (result == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(Request.CreateResponse <BatchProcessingWorkflowDTO>(HttpStatusCode.OK, result)); }
private void FillDisplayImage(BlobImage blobImage, Bitmap bmpTemp) { // Get Location from Context Rectangle rect = new Rectangle(blobImage.Location.X, blobImage.Location.Y, bmpTemp.Width, bmpTemp.Height); // Create BRAND F*****G NEW Bitmap using (Bitmap newBitmap = new Bitmap(blobImage.Source.Size.Width, blobImage.Source.Size.Height)) { Graphics gfx = Graphics.FromImage(newBitmap); gfx.Clear(blobImage.BitmapBlob.BackgroundIsBlack ? Color.Black : Color.White); gfx.DrawImage(bmpTemp, rect); // Update the Display SetDisplayImage(newBitmap); #if DEBUG // Debugging if (Settings.Default.ImagingSettings.DebugRecognitionSaveImages) { ImageDump(newBitmap, "Post"); } #endif } }
public async Task <IActionResult> OnPost() { // Make the call to our DB with our ID. var post = await _post.GetSinglePost(ID.GetValueOrDefault()) ?? new Posts(); // set the data from the database to the new data post.Author = Post.Author; post.ImageURL = Post.ImageURL; post.Capture = Post.Capture; if (Image != null) { var filePath = Path.GetTempFileName(); using (var stream = new FileStream(filePath, FileMode.Create)) { await Image.CopyToAsync(stream); } //Get Container var container = await BlobImage.GetContainer("images"); //upload the image BlobImage.UploadFile(container, Image.FileName, filePath); CloudBlob blob = await BlobImage.GetBlob(Image.FileName, container.Name); //update the db image for the post post.ImageURL = blob.Uri.ToString(); } // Save the post in the database await _post.SaveAsync(post); return(RedirectToPage("/Grams/Index", new { id = post.ID })); }
public void Render(Grid.GridRange range, Rectangle viewport) { // 1. Remove previous tiles. //// foreach (var cellList in visibleCells.Values) { cellList.Clear(); } // 1. Fill //// foreach (Grid.GridCell cell in range) { if (cell.Data == null) { continue; } BlobImage image = cell.Data.Floor.Image; if (!visibleCells.ContainsKey(image)) { Bitmap bitmap = image.Image; using (Stream s = new MemoryStream()) { bitmap.Save(s, ImageFormat.Png); s.Seek(0, SeekOrigin.Begin); Texture tex = Texture.FromStream(device, s, bitmap.Width, bitmap.Height, 0, Usage.None, Format.Unknown, Pool.Managed, Filter.None, Filter.None, 0); textures.Add(image, tex); visibleCells.Add(image, new List <TexturedVertex>()); } } List <TexturedVertex> currentList = visibleCells[image]; int pixelsPerCell = 8; int x = (cell.X * pixelsPerCell) - viewport.X; int y = (cell.Y * pixelsPerCell) - viewport.Y; int w = 8; int h = 8; // Calculate the (u,v) we need to use based on the tile coordinates. float scaleW = 8.0f / image.Image.Width; float scaleH = 8.0f / image.Image.Height; float uStart = cell.X * scaleW; float vStart = cell.Y * scaleH; float uEnd = uStart + scaleW; float vEnd = vStart + scaleH; // Clockwise winding // TODO: Index these vertices! argh var v0 = new TexturedVertex(new Vector4(x, y, RenderingZOffset, 1.0f), new Vector2(uStart, vStart)); var v1 = new TexturedVertex(new Vector4(x + w, y, RenderingZOffset, 1.0f), new Vector2(uEnd, vStart)); var v2 = new TexturedVertex(new Vector4(x + w, y + h, RenderingZOffset, 1.0f), new Vector2(uEnd, vEnd)); var v3 = new TexturedVertex(new Vector4(x, y, RenderingZOffset, 1.0f), new Vector2(uStart, vStart)); var v4 = new TexturedVertex(new Vector4(x + w, y + h, RenderingZOffset, 1.0f), new Vector2(uEnd, vEnd)); var v5 = new TexturedVertex(new Vector4(x, y + h, RenderingZOffset, 1.0f), new Vector2(uStart, vEnd)); currentList.Add(v0); currentList.Add(v1); currentList.Add(v2); currentList.Add(v3); currentList.Add(v4); currentList.Add(v5); } // 2. Fill buffer. //// DataStream stream = vertexBuffer.Lock(0, 0, LockFlags.Discard); foreach (var vertexList in visibleCells) { if (vertexList.Value.Count == 0) { continue; } stream.WriteRange(vertexList.Value.ToArray()); } vertexBuffer.Unlock(); // 3. Draw. //// device.SetSamplerState(0, SamplerState.MinFilter, TextureFilter.Linear); device.SetStreamSource(0, vertexBuffer, 0, TexturedVertex.Size); device.VertexDeclaration = vertexDecl; int offset = 0; foreach (var vertexList in visibleCells) { var texture = textures[vertexList.Key]; device.SetTexture(0, texture); int tilesToDraw = vertexList.Value.Count / 3; device.DrawPrimitives(PrimitiveType.TriangleList, offset, tilesToDraw); offset += tilesToDraw * 3; } }
public HttpResponseMessage FileUpload(int docTypeId, bool test) { try { int userID = int.Parse(Request.Headers.GetValues("userId").FirstOrDefault()); var org = _IUserService.GetUser(userID).OrgUsers.Where(p => p.Type == null || p.Type.Contains("Primary")).FirstOrDefault().Org; var docType = org.OrgDocTyps.Where(p => p.Id == docTypeId).FirstOrDefault(); var path = ""; System.Web.HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files; int iUploadedCnt = 0; string fileName = ""; var guid = org.soKey; Guid parentGuid = Guid.Empty; if (org.Id != 1) { parentGuid = org.OrgOrgs1.FirstOrDefault().Org.soKey; } #region Upload to Blob var status = ""; var storageKey = Guid.NewGuid(); var storageAccess = _IPortsettingService.GetPortsettings().Where(p => p.PortId == 1 && p.Setting.Name == "StorageAccess").FirstOrDefault().PortSettingValues.FirstOrDefault().Value; //var storageContainer = _IPortsettingService.GetPortsettings().Where(p => p.PortId == 1 && p.Setting.Name == "StorageContainer").FirstOrDefault().PortSettingValues.FirstOrDefault().Value; var versionData = new VersionData(); versionData.container = guid.ToString(); versionData.accountKey = storageAccess; var success = false; for (int iCnt = 0; iCnt <= hfc.Count - 1; iCnt++) { System.Web.HttpPostedFile hpf = hfc[iCnt]; if (hpf.ContentLength > 0) { BinaryReader b = new BinaryReader(hpf.InputStream); byte[] binData = b.ReadBytes(hpf.ContentLength); success = BlobImage.UploadImage(hpf.FileName, binData, storageKey.ToString() + ".UPL", versionData, org.soKey.ToString(), hpf.FileName); fileName = hpf.FileName; iUploadedCnt = iUploadedCnt + 1; } } #endregion if (iUploadedCnt > 0 && success) { status = iUploadedCnt + " Files Uploaded Successfully"; var batchProcessingWorkflow = _IWkflowdefService.GetWkflowdefs().Where(p => p.Code == "FPW").FirstOrDefault(); var UploadingstatusID = batchProcessingWorkflow.WkflowDefWkflowStats.Where(p => p.WkflowStat.Code == "UPLOADED").FirstOrDefault().WkflowStatId; // Create a new batch processing workflow var batchWkflowInstance = new WkflowInstance { CreateDate = DateTime.UtcNow, DateLastMaint = DateTime.UtcNow, WkflowDefId = batchProcessingWorkflow.Id, OrgId = org.Id, UserId = userID, CurrWkflowStatId = UploadingstatusID }; // Set INIT state for new workflow instance. batchWkflowInstance.WkflowStepHists.Add(new WkflowStepHist { CreateDate = DateTime.UtcNow, DateLastMaint = DateTime.UtcNow, WkflowStatId = UploadingstatusID, CreatedUserId = userID }); var wkflowInstanceDoc = new WkflowInstanceDoc { WkflowInstanceId = batchWkflowInstance.Id, Doc = new soUpload { Name = fileName, Descript = fileName, soFileName = fileName, OrgDocTypId = docTypeId, soStorageLocation = path, soStorageKey = storageKey.ToString() + ".UPL", soStorageContainer = guid.ToString(), soUploadApp = "WebPortal", soUploadAppVersion = "1.0.0.0", soUploadDurationMS = 10, soStorageType = "Local", soFormType = docType.Descript, soFormTypesKey = docType.soKey, soUserData = "", soUploadTime = DateTime.UtcNow, soKey = storageKey, soMethod = "Web", soWorkstation = "Portal", soOrganizationsKey = guid, soParentOrganizationsKey = parentGuid, soUserID = userID.ToString(), OrgId = org.Id, FileTypeId = 2, FileExt = Path.GetExtension(fileName), soTest = test } }; batchWkflowInstance.WkflowInstanceDocs.Add(wkflowInstanceDoc); _IWkflowinstanceService.AddWkflowinstance(batchWkflowInstance); } else { var createresponse = Request.CreateErrorResponse(HttpStatusCode.NotFound, "Upload Failed"); throw new HttpResponseException(createresponse); } return(Request.CreateResponse <string>(HttpStatusCode.OK, status)); } catch { var createresponse = Request.CreateErrorResponse(HttpStatusCode.NotFound, "Upload Failed"); throw new HttpResponseException(createresponse); } }
private void OnObjectSelected(BlobImage blob) { selectedBlobImage = blob; }
private void OnFloorSelected(BlobImage blob) { selectedBlobImage = blob; }