Exemple #1
0
        /// <summary>
        /// Clips the bitmap according to the provided shape and plane. The BitmapBits are replaced by
        /// transparent pixels, the original bits are lost. Setting another clip area doesn't restore already clipped
        /// pixels. (Ofcourse undo restores the original bitmap bits)
        /// </summary>
        /// <param name="plane">The plane as a reference system for the shape</param>
        /// <param name="shape">The shape for the clip operation</param>
        public void Clip(Plane plane, CompoundShape shape)
        {
#if !WEBASSEMBLY
            Plane         pln  = new Plane(location, directionWidth, directionHeight);
            CompoundShape prsh = shape.Project(plane, pln);
            ModOp2D       m    = ModOp2D.Scale(bitmap.Width / directionWidth.Length, -bitmap.Height / directionHeight.Length);
            prsh = prsh.GetModified(m);
            m    = ModOp2D.Translate(0, bitmap.Height);
            prsh = prsh.GetModified(m);
            GraphicsPath gp = prsh.CreateGraphicsPath();
            using (new Changing(this))
            {
                Region   rg       = new Region(gp);
                Bitmap   clone    = bitmap.Clone() as Bitmap;
                Graphics graphics = Graphics.FromImage(bitmap);
                graphics.Clear(Color.FromArgb(0, 0, 0, 0));
                graphics.SetClip(rg, CombineMode.Replace);
                graphics.DrawImage(clone, new System.Drawing.Point(0, 0));
                graphics.Dispose();
            }
#endif
        }
Exemple #2
0
 /// <summary>
 /// Overrides IGeoObjectImpl.<see cref="IGeoObjectImpl.Modify"/> and implements IGeoObject.<see cref="IGeoObject.Modify"/>.
 /// </summary>
 /// <param name="m">see <see cref="IGeoObject.Modify"/></param>
 public override void Modify(ModOp m)
 {
     using (new Changing(this, "ModifyInverse", m))
     {
         // die ModOp wird in zwei Komponente aufgeteilt:
         // eine Skalierungsfreie, die auf die Ebene angewendet wird
         // und eine Skalierung, die nochmal auf die compoundShape wirkt
         try
         {
             Plane newPlane = new Plane(m * plane.Location, m * plane.DirectionX, m * plane.DirectionY);
             // die Ebene verändert sich gemäß der Matrix m, wie verändert sich die Umrandung im 2D?
             // Die brutale Methode: aus den bekannten Veränderungen von 3 Punkten die Matrix bestimmen
             // das funktioniert, alles andere hat bislang nicht geklappt
             GeoPoint2D[] src = new GeoPoint2D[3];
             GeoPoint2D[] dst = new GeoPoint2D[3];
             src[0] = GeoPoint2D.Origin;
             src[1] = GeoPoint2D.Origin + GeoVector2D.XAxis;
             src[2] = GeoPoint2D.Origin + GeoVector2D.YAxis;
             dst[0] = newPlane.Project(m * plane.ToGlobal(src[0]));
             dst[1] = newPlane.Project(m * plane.ToGlobal(src[1]));
             dst[2] = newPlane.Project(m * plane.ToGlobal(src[2]));
             ModOp2D m2d = ModOp2D.Fit(src, dst, true);
             compoundShape = compoundShape.GetModified(m2d);
             plane         = newPlane;
             if (m.Mode == ModOp.ModificationMode.Translation && base.Count > 0)
             {
                 containedObjects.Modify(m);
             }
             else
             {
                 needsRecalc = true;
             }
         }
         catch (PlaneException) { } // neue Ebene enthält Nullvector
     }
 }