public void ImageLoadingGetOriginalImageSize() { tlog.Debug(tag, $"ImageLoadingGetOriginalImageSize START"); var testingTarget = ImageLoading.GetOriginalImageSize("picture"); Assert.IsNotNull(testingTarget, "Can't create success object Size2D."); Assert.IsInstanceOf <Size2D>(testingTarget, "Should return Size2D instance."); testingTarget.Dispose(); tlog.Debug(tag, $"ImageLoadingGetOriginalImageSize END (OK)"); }
protected override void OnCreate() { base.OnCreate(); win = Window.Instance; win.BackgroundColor = Color.Cyan; View v1 = new View(); v1.Size2D = new Size2D(100, 100); v1.BackgroundColor = Color.Blue; win.GetDefaultLayer().Add(v1); ImageView iv = new ImageView(); iv.ResourceUrl = mypath.DirectoryInfo.Resource + @"/images/Dali/DaliDemo/Logo-for-demo.png"; iv.Position2D = new Position2D(50, 200); win.GetDefaultLayer().Add(iv); Size2D imageSize = ImageLoading.GetOriginalImageSize(iv.ResourceUrl); TextLabel tl = new TextLabel(); tl.Position2D = new Position2D(iv.Position2D.X, iv.Position2D.Y + imageSize.Height); tl.MultiLine = true; tl.Text = $"ResourceUrl: {iv.ResourceUrl} \nOriginalImageSize: W({imageSize.Width}), H({imageSize.Height})"; win.GetDefaultLayer().Add(tl); //================== iv = new ImageView(); iv.ResourceUrl = mypath.DirectoryInfo.Resource + @"/images/Dali/DaliDemo/demo-tile-texture.9.png"; iv.Position2D = new Position2D(50, 600); win.GetDefaultLayer().Add(iv); imageSize = ImageLoading.GetOriginalImageSize(iv.ResourceUrl); tl = new TextLabel(); tl.Position2D = new Position2D(iv.Position2D.X, iv.Position2D.Y + imageSize.Height); tl.MultiLine = true; tl.Text = $"ResourceUrl: {iv.ResourceUrl} \nOriginalImageSize: W({imageSize.Width}), H({imageSize.Height})"; win.GetDefaultLayer().Add(tl); }
private void UpdateImage(int key, PropertyValue value) { PropertyMap temp = new PropertyMap(); if (_alphaMaskUrl != null) { temp.Insert(ImageVisualProperty.AlphaMaskURL, new PropertyValue(_alphaMaskUrl)); } if (_resourceUrl == "") { temp.Insert(ImageVisualProperty.URL, new PropertyValue(_resourceUrl)); SetProperty(ImageView.Property.IMAGE, new PropertyValue(temp)); return; } if (_border == null) { temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image)); } else { temp.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.NPatch)); temp.Insert(NpatchImageVisualProperty.Border, new PropertyValue(_border)); } temp.Insert(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue(_synchronosLoading)); if (backgroundExtraData != null && backgroundExtraData.CornerRadius > 0) { temp.Insert(Visual.Property.CornerRadius, new PropertyValue(backgroundExtraData.CornerRadius)); } if (value != null) { temp.Insert(key, value); } // Do Fitting Buffer when desired dimension is set if (_desired_width != -1 && _desired_height != -1) { if (_resourceUrl != null) { Size2D imageSize = ImageLoading.GetOriginalImageSize(_resourceUrl); int ret_width, ret_height; if (imageSize.Width > imageSize.Height) { ret_width = _desired_width; ret_height = imageSize.Height * _desired_height / (imageSize.Width); } else { ret_width = imageSize.Width * _desired_width / (imageSize.Height); ret_height = _desired_height; } temp.Insert(ImageVisualProperty.DesiredWidth, new PropertyValue((int)ret_width)); temp.Insert(ImageVisualProperty.DesiredHeight, new PropertyValue((int)ret_height)); temp.Insert(ImageVisualProperty.FittingMode, new PropertyValue((int)FittingModeType.ShrinkToFit)); } } UpdateImageMap(temp); temp.Dispose(); temp = null; }