static void AddImageToPage(ImageData tex, string Id) { HTMLDivElement div = new HTMLDivElement(); div.ClassName = "col"; div.Style.Padding = "5px"; HTMLCanvasElement c = new HTMLCanvasElement(); c.Id = Id; c.ClassName = "CustomCanvas"; c.Style.BackgroundColor = "#FAFAFA"; ImageEncoding.ImageType imgType = ImageEncoding.ImageTypesByID[t.NameToImageID(Id)]; c.Height = imgType.s.y; c.Width = imgType.s.x; c.OnClick = ImageCanvasClick; c.Style.Margin = "auto"; c.Style.Border = "black 3px solid"; div.AppendChild(MakeImageLabel(Id, imgType.s.x.ToString() + "x" + imgType.s.y.ToString())); if (Id != Theme.Name_TopScr && Id != Theme.Name_BotScr) { div.AppendChild(MakeImageEnableCheckBox(Id, tex != null)); } else { HtmlCanvasFitSize(c, imgType.s); } div.AppendChild(c); ImagesDiv.AppendChild(div); if (tex != null) { ((CanvasRenderingContext2D)c.GetContext("2d")).PutImageData(tex, 0, 0); } }
static void UpdateShownImg(ImageEncoding.ImageType imgType, string ID, ImageData img) { HTMLCanvasElement ShownImg = Document.GetElementById <HTMLCanvasElement>(ID); ShownImg.Width = imgType.s.x; ShownImg.Height = imgType.s.y; ((CanvasRenderingContext2D)ShownImg.GetContext("2d")).PutImageData(img, 0, 0); }
static void ApplyImage(HTMLCanvasElement tmpImg) { ImageEncoding.ImageType imgType = ImageEncoding.ImageTypesByID[t.NameToImageID(ImageInputSenderID)]; HTMLCanvasElement FinalCanvas = new HTMLCanvasElement(); FinalCanvas.Width = imgType.s.x; FinalCanvas.Height = imgType.s.y; if (tmpImg == null) { t.GetTexture(ImageInputSenderID).tex = null; var context = ((CanvasRenderingContext2D)FinalCanvas.GetContext("2d")); context.FillRect(0, 0, imgType.s.x, imgType.s.y); } else if (tmpImg.Width == imgType.ActualSize.x && tmpImg.Height == imgType.ActualSize.y) { var context = ((CanvasRenderingContext2D)FinalCanvas.GetContext("2d")); context.FillRect(0, 0, imgType.s.x, imgType.s.y); context.DrawImage(tmpImg, 0, 0); } else if (tmpImg.Width == imgType.s.x && tmpImg.Height == imgType.s.y) { FinalCanvas = tmpImg; } else { var context = ((CanvasRenderingContext2D)FinalCanvas.GetContext("2d")); context.FillRect(0, 0, imgType.s.x, imgType.s.y); context.DrawImage(tmpImg, 0, 0, imgType.ActualSize.x, imgType.ActualSize.y); } var img = ((CanvasRenderingContext2D)FinalCanvas.GetContext("2d")).GetImageData(0, 0, imgType.s.x, imgType.s.y); t.GetTexture(ImageInputSenderID).tex = tmpImg == null ? null : img; UpdateShownImg(imgType, ImageInputSenderID, img); }