private IImage GetScaledImage(Bitmap?img,
                                      Stream?stream,
                                      Double imgDesiredWidth,
                                      Boolean isPreserveStream)
        {
            if (img == null)
            {
                return(GetNullImage());
            }

            if (imgDesiredWidth.AreEqualEnough(img.Width))
            {
                return(isPreserveStream
                    ? new AndroidBitmap(img, stream)
                    : new AndroidBitmap(img, null));
            }

            var scaleRatio = imgDesiredWidth / img.Width;

            var width  = Convert.ToInt32(img.Width * scaleRatio);
            var height = Convert.ToInt32(img.Height * scaleRatio);

            var scaledBitmap = Bitmap.CreateScaledBitmap(img,
                                                         width, height, true);

            img.Dispose();
            return(new AndroidBitmap(scaledBitmap !, null));
        }
Ejemplo n.º 2
0
        public ScaleTransform(Double scaleX,
                              Double scaleY)
        {
            ScaleX = scaleX;
            ScaleY = scaleY;

            IsIdentity = ScaleX.AreEqualEnough(1.0) && ScaleY.AreEqualEnough(1.0);

            Value = IsIdentity
                ? TransformationMatrix.Identity
                : new TransformationMatrix(scaleX, 0, 0, scaleY, 0, 0);
        }
        public Boolean TrySetZoomLevel(Double zoom)
        {
            if (ZoomLevel.AreEqualEnough(zoom))
            {
                return(true);
            }

            if (zoom < _minZoomLevel || zoom > _maxZoomLevel)
            {
                return(false);
            }

            ZoomLevel = zoom;
            IsChanged = true;
            return(true);
        }
Ejemplo n.º 4
0
        public Boolean UpdateSize(Double width,
                                  Double height)
        {
            lock (_sizeLock)
            {
                if (width.AreEqualEnough(_width) &&
                    height.AreEqualEnough(_height))
                {
                    return(false);
                }

                if (width.IsZero() ||
                    height.IsZero())
                {
                    return(false);
                }

                if (_currentDib != IntPtr.Zero)
                {
                    Native.DeleteObject(_currentDib);
                }

                _bmp.Dispose();
                _dcGraphics?.Dispose();

                if (_memoryDeviceContext != IntPtr.Zero)
                {
                    DeleteDC(_memoryDeviceContext);
                }

                var iwidth  = Convert.ToInt32(width);
                var iheight = Convert.ToInt32(height);

                //////////////////////////////////
                if (!Invalidate(iwidth, iheight, _backgroundColor))
                {
                    return(false);
                }
                //////////////////////////////////

                _bmp = new Bitmap(iwidth, iheight);
                using (var g = _bmp.GetSmoothGraphics())
                    g.Clear(_backgroundColor);

                return(true);
            }
        }
        public TransformationMatrix(Double scaleX,
                                    Double skewX,
                                    Double skewY,
                                    Double scaleY,
                                    Double offsetX,
                                    Double offsetY)
        {
            ScaleX  = scaleX;
            SkewX   = skewX;
            SkewY   = skewY;
            ScaleY  = scaleY;
            OffsetX = offsetX;
            OffsetY = offsetY;

            _aboutMe = "";
            if (OffsetX.IsNotZero())
            {
                _aboutMe += "Offset-X: " + OffsetX;
            }

            if (OffsetY.IsNotZero())
            {
                _aboutMe += " Offset-Y: " + OffsetY;
            }

            if (String.IsNullOrEmpty(_aboutMe))
            {
                _aboutMe = "Identity";
            }

            IsIdentity = offsetX.IsZero() &&
                         offsetY.IsZero() &&
                         scaleX.AreEqualEnough(1.0) &&
                         scaleY.AreEqualEnough(1.0) &&
                         skewX.IsZero() &&
                         skewY.IsZero();
        }