/// <summary>Creates a single UI element for the given HTML node and HTML view.</summary> /// <param name="node">The node.</param> /// <param name="htmlView">The text block.</param> /// <returns>The UI element.</returns> public override DependencyObject CreateControl(HtmlNode node, IHtmlView htmlView) { try { var imageUri = node.Attributes["src"]; var height = 0; if (node.Attributes.ContainsKey("height")) int.TryParse(node.Attributes["height"], out height); var width = 0; if (node.Attributes.ContainsKey("width")) int.TryParse(node.Attributes["width"], out width); if (height == 1 && width == 1) return null; var image = new Image(); image.Width = 0; image.Height = 0; var bitmapImage = new BitmapImage(new Uri(imageUri)); var imageBlock = new ImageBlock { Image = image, UserHeight = height, UserWidth = width, Source = bitmapImage }; bitmapImage.ImageOpened += delegate { imageBlock.Update(htmlView.ActualWidth); }; image.HorizontalAlignment = HorizontalAlignment.Left; image.Source = bitmapImage; image.Margin = new Thickness(0, htmlView.ParagraphMargin, 0, htmlView.ParagraphMargin); if (width > 0) image.Width = width; if (height > 0) image.Height = height; htmlView.SizeDependentControls.Add(imageBlock); return new ContentPresenter { Content = image }; } catch { return null; } }
public override DependencyObject GenerateSingle(HtmlNode node, IHtmlTextBlock textBlock) { try { var uri = node.Attributes["src"]; var height = 0; if (node.Attributes.ContainsKey("height")) int.TryParse(node.Attributes["height"], out height); var width = 0; if (node.Attributes.ContainsKey("width")) int.TryParse(node.Attributes["width"], out width); if (height == 1 && width == 1) return null; var image = new Image(); var imgSource = new BitmapImage(new Uri(uri)); var block = new ImageBlock { Image = image, UserHeight = height, UserWidth = width, Source = imgSource }; imgSource.ImageOpened += delegate { block.Update(textBlock.ActualWidth); }; image.HorizontalAlignment = HorizontalAlignment.Left; image.Source = imgSource; image.Margin = new Thickness(0, textBlock.ParagraphMargin, 0, textBlock.ParagraphMargin); if (width > 0) image.Width = width; if (height > 0) image.Height = height; textBlock.SizeDependentControls.Add(block); return image; } catch { return null; } }
static void SetImageBlock (byte[] gifBytes, ref int byteIndex, ref GifData gifData) { ImageBlock ib = new ImageBlock (); // Image Separator(1 Byte) // 0x2c ib.imageSeparator = gifBytes[byteIndex]; byteIndex++; // Image Left Position(2 Bytes) ib.imageLeftPosition = BitConverter.ToUInt16 (gifBytes, byteIndex); byteIndex += 2; // Image Top Position(2 Bytes) ib.imageTopPosition = BitConverter.ToUInt16 (gifBytes, byteIndex); byteIndex += 2; // Image Width(2 Bytes) ib.imageWidth = BitConverter.ToUInt16 (gifBytes, byteIndex); byteIndex += 2; // Image Height(2 Bytes) ib.imageHeight = BitConverter.ToUInt16 (gifBytes, byteIndex); byteIndex += 2; // 1 Byte { // Local Color Table Flag(1 Bit) ib.localColorTableFlag = (gifBytes[byteIndex] & 128) == 128; // 0b10000000 // Interlace Flag(1 Bit) ib.interlaceFlag = (gifBytes[byteIndex] & 64) == 64; // 0b01000000 // Sort Flag(1 Bit) ib.sortFlag = (gifBytes[byteIndex] & 32) == 32; // 0b00100000 // Reserved(2 Bits) // Unused // Size of Local Color Table(3 Bits) int val = (gifBytes[byteIndex] & 7) + 1; ib.sizeOfLocalColorTable = (int) Math.Pow (2, val); byteIndex++; } if (ib.localColorTableFlag) { // Local Color Table(0~255×3 Bytes) ib.localColorTable = new List<byte[]> (); for (int i = byteIndex; i < byteIndex + (ib.sizeOfLocalColorTable * 3); i += 3) { ib.localColorTable.Add (new byte[] { gifBytes[i], gifBytes[i + 1], gifBytes[i + 2] }); } byteIndex = byteIndex + (ib.sizeOfLocalColorTable * 3); } // LZW Minimum Code Size(1 Byte) ib.LzwMinimumCodeSize = gifBytes[byteIndex]; byteIndex++; // Block Size & Image Data List while (true) { // Block Size(1 Byte) byte blockSize = gifBytes[byteIndex]; byteIndex++; if (blockSize == 0x00) { // Block Terminator(1 Byte) break; } var imageDataBlock = new ImageBlock.ImageDataBlock (); imageDataBlock.blockSize = blockSize; // Image Data(? Bytes) imageDataBlock.imageData = new byte[imageDataBlock.blockSize]; for (int i = 0; i < imageDataBlock.imageData.Length; i++) { imageDataBlock.imageData[i] = gifBytes[byteIndex]; byteIndex++; } if (ib.imageDataList == null) { ib.imageDataList = new List<ImageBlock.ImageDataBlock> (); } ib.imageDataList.Add (imageDataBlock); } if (gifData.imageBlockList == null) { gifData.imageBlockList = new List<ImageBlock> (); } gifData.imageBlockList.Add (ib); }
public ImageListViewItem(ImageBlock ib) : base() { this.ImageBlock = ib; }
/// <summary> /// Set texture pixel row /// </summary> static void SetTexturePixelRow (Texture2D tex, int y, ImageBlock imgBlock, byte[] decodedData, ref int dataIndex, List<byte[]> colorTable, Color32? bgColor, int transparentIndex, bool useBeforeTex) { // Row no (0~) int row = tex.height - 1 - y; for (int x = 0; x < tex.width; x++) { // Line no (0~) int line = x; // Out of image blocks if (row < imgBlock.imageTopPosition || row >= imgBlock.imageTopPosition + imgBlock.imageHeight || line < imgBlock.imageLeftPosition || line >= imgBlock.imageLeftPosition + imgBlock.imageWidth) { if (useBeforeTex == false && bgColor != null) { tex.SetPixel (x, y, bgColor.Value); } continue; } // Out of decoded data if (dataIndex >= decodedData.Length) { tex.SetPixel (x, y, Color.black); // Debug.LogError ("dataIndex exceeded the size of decodedData. dataIndex:" + dataIndex + " decodedData.Length:" + decodedData.Length + " y:" + y + " x:" + x); dataIndex++; continue; } // Get pixel color from color table byte colorIndex = decodedData[dataIndex]; if (colorTable == null || colorTable.Count <= colorIndex) { Debug.LogError ("colorIndex exceeded the size of colorTable. colorTable.Count:" + colorTable.Count + " colorIndex:" + colorIndex); dataIndex++; continue; } byte[] rgb = colorTable[colorIndex]; // Set alpha byte alpha = transparentIndex >= 0 && transparentIndex == colorIndex ? (byte) 0 : (byte) 255; if (alpha != 0 || useBeforeTex == false) { Color32 col = new Color32 (rgb[0], rgb[1], rgb[2], alpha); tex.SetPixel (x, y, col); } dataIndex++; } }
/// <summary> /// Get color table (local or global) /// </summary> static List<byte[]> GetColorTable (GifData gifData, ImageBlock imgBlock, ref Color32? bgColor) { var colorTable = imgBlock.localColorTableFlag ? imgBlock.localColorTable : gifData.globalColorTable; if (imgBlock.localColorTableFlag) { // Set background color from local color table byte[] bgRgb = imgBlock.localColorTable[gifData.bgColorIndex]; bgColor = new Color32 (bgRgb[0], bgRgb[1], bgRgb[2], 255); } return colorTable; }
/// <summary> /// Get decoded image data from ImageBlock /// </summary> static byte[] GetDecodedData (ImageBlock imgBlock) { // Combine LZW compressed data List<byte> lzwData = new List<byte> (); foreach (var imageData in imgBlock.imageDataList) { foreach (var data in imageData.imageData) { lzwData.Add (data); } } // LZW decode int needDataSize = imgBlock.imageHeight * imgBlock.imageWidth; byte[] decodedData = DecodeGifLZW (lzwData, imgBlock.LzwMinimumCodeSize, needDataSize); // Sort interlace GIF if (imgBlock.interlaceFlag) { decodedData = SortInterlaceGifData (decodedData, imgBlock.imageWidth); } return decodedData; }
//User section for bussines logic //Your code should be inserted here protected async Task UserSection() { _screenView = Screen.CreateElement("Design.ScreenView"); _screenList = Screen.CreateElement("Design.ScreenList"); _screenInfo = Screen.CreateElement("Design.ScreenInfo"); _state = AppState.List; #region init // load Screen List controls screenList_List = _screenList.GetChildByName("MainList") as ListBox; screenList_List.Clickable = true; screenList_List.Clicked += screenList_List_Clicked; screenList_BtAdd = _screenList.GetChildByName("BtAdd") as SelectableArea; screenList_BtAdd.Clicked += screenList_BtAdd_Clicked; // load screen info controls _screenInfo_Caption = _screenInfo.GetChildByName("tbCaption") as TextBlock; _screenInfo_MainText = _screenInfo.GetChildByName("tbMainText") as TextBlock; _screenInfo_BtBack = _screenInfo.GetChildByName("BtBack") as SelectableArea; _screenInfo_BtBack.Clicked += BackToSCreenList; // load screen view controls _screenView_Image = _screenView.GetChildByName("MainImage") as ImageBlock; _screenView_CameraName = _screenView.GetChildByName("TlName") as TextBlock; _screenView_BtBack = _screenView.GetChildByName("BtBack") as SelectableArea; _screenView_BtBack.Clicked += BackToSCreenList; // qrcode reader _barcodeReader = new BarcodeReader(this); _barcodeReader.BarcodeReady += (s, be) => { if (_barcodeReader.RC == FunctionRC.OK) { AddCamera(_barcodeReader.MainData); } else { // todo error reporting //barcodeState = TPositioningState.ErrorReceived; } }; #endregion _cameras = new List<string>(); _state = AppState.List; AddCamera("100-066e23cd012e8f79afc37722e07bf694"); AddCamera("100-f0a176294a5c51a822ee6f4c0ae89a2c"); AddCamera("100-2033519638a3a4abb9b41d3a04bdb666"); #if false // можно включить AddCamera("100-2fbb74c566c49f4cfb6e2ea2ce1c9b4d"); AddCamera("100-40580f419398b68e0a18fa0fc319101b"); AddCamera("100-1bb9cf88076de6341a294182a49c6cf5"); #endif for (; ; ) { switch (_state) { case AppState.List: Screen.Content = _screenList; break; case AppState.StartingView: // start timer Schedule(1000, GetPicture); _screenInfo_Caption.Text = "Подключение"; _screenInfo_MainText.Text = "Пожалуйста, подождите. Идет подключение..."; Screen.Content = _screenInfo; break; case AppState.View: _screenView_Image.Image = _lastImage; _screenView_CameraName.Text = _cameras[_activeCamera]; Screen.Content = _screenView; break; case AppState.Error: Screen.Content = _screenInfo; break; } await Wait(); } }