Пример #1
0
        ICanvasImage GetMagicWandMask(List <Vector2> points, float zoomFactor)
        {
            // What color did the user click on?
            Vector2 clickPoint = Vector2.Clamp(points.First(), Vector2.Zero, SourceBitmap.Size.ToVector2() - Vector2.One);

            Color clickColor = SourceBitmap.GetPixelColors((int)clickPoint.X, (int)clickPoint.Y, 1, 1).Single();

            // How far they have dragged = selection tolerance.
            float dragDistance = Vector2.Distance(points.First(), points.Last());

            float chromaTolerance = Math.Min(dragDistance / 512 * zoomFactor, 1);

            return(new ColorMatrixEffect
            {
                Source = new ChromaKeyEffect
                {
                    Source = SourceBitmap,
                    Color = clickColor,
                    Tolerance = chromaTolerance,
                    InvertAlpha = true
                },

                ColorMatrix = new Matrix5x4
                {
                    // Preserve alpha.
                    M44 = 1,

                    // Set RGB = white.
                    M51 = 1,
                    M52 = 1,
                    M53 = 1,
                }
            });
        }
Пример #2
0
        public void Dispose()
        {
            if (iDisposed)
            {
                return;
            }

            try
            {
                if (SourceBitmap != null)
                {
                    if (SourceBitmap.Tag != null && SourceBitmap.Tag is BitmapTag)
                    {
                        System.IO.Stream s = ((BitmapTag)SourceBitmap.Tag).Source;
                        if (s != null)
                        {
                            s.Dispose();
                        }
                    }
                    SourceBitmap.Dispose();
                }
            }
            finally {
                if (destinationBitmap != null)
                {
                    destinationBitmap.Dispose();
                }
            }
            iDisposed = true;
            GC.SuppressFinalize(this);
        }
        public void SetBytes(byte[] pixels, int x, int y, int width, int height)
        {
            Int32Rect cutArea = new Int32Rect(x, y, width, height);

            //SourceBitmap.Lock();
            SourceBitmap.CopyPixels(cutArea, BitmapBytes, Stride, 0);
            //SourceBitmap.Unlock();
            BitmapSource    newBitmap  = BitmapSource.Create(width, height, 96.0, 96.0, PixelFormats.Bgr32, null, BitmapBytes, Stride);
            WriteableBitmap tempBitmap = new WriteableBitmap(newBitmap);

            Initialize(tempBitmap);
            //SourceBitmap.WritePixels(new Int32Rect(0, 0, width, height), pixels, Stride, 0);
        }
Пример #4
0
        /// <summary>
        /// zapise PropertyItem do obrazku
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public void SetPropertyItem(PropertyTagId TagId, string Text)
        {
            CheckSrcBitmap();

            // ziskani nove instance PropertyItem
            Encoding     EncAscii = Encoding.ASCII;
            PropertyItem NewPItem = CreatePropertyItem(PropertyTagType.ASCII, TagId, Text.Length, EncAscii.GetBytes(Text));

            // zapis do Bitmapy
            if (NewPItem != null)
            {
                SourceBitmap.SetPropertyItem(NewPItem);
            }
        }
Пример #5
0
 private void Dispose(bool Disposing)
 {
     if (!Disposed)
     {
         Disposed = true;
         SourceBitmap.Dispose();
         SourceHandle.Free();
         GrayScaleBitmap.Dispose();
         GrayScaleHandle.Free();
         ProcessedBitmap.Dispose();
         ProcessedHandle.Free();
         if (Disposing)
         {
             SourceBitmap    = null;
             SourceArr       = null;
             GrayScaleBitmap = null;
             GrayScaleArr    = null;
             ProcessedBitmap = null;
             ProcessedArr    = null;
         }
     }
 }