コード例 #1
0
        void img_PointerReleased(object sender, PointerRoutedEventArgs e)
        {
            si = Target.getImage();
            if (si.Source == null)
            {
                return;
            }
            //double dx = Canvas.GetLeft(si) + Canvas.GetLeft(Target.SelectLayer);
            //double dy = Canvas.GetTop(si) + Canvas.GetTop(Target.SelectLayer);
            Point ep = e.GetCurrentPoint(si).Position;

            if (Math.Abs(sp.X - ep.X) < 1.1 && Math.Abs(sp.Y - ep.Y) < 1.1)
            {
                Point tp = DrawGraphic.getImagePosition(sp, si);
                Color c  = pt.GetPixel(si.Source as WriteableBitmap, Convert.ToInt32(tp.X), Convert.ToInt32(tp.Y));
                ShowColor(c);
                sb = null;
                sb = new WriteableBitmap(1, 1);
                pt.SetPixel(sb, 0, 0, c);
                ColorImg.Source = sb;
                //ColorImg.
            }
            else
            {
                int   sx, sy, w, h;
                Point isp = DrawGraphic.getImagePosition(sp, si);
                Point iep = DrawGraphic.getImagePosition(ep, si);
                if (isp.X < iep.X)
                {
                    sx = Convert.ToInt32(isp.X);
                    w  = Convert.ToInt32(iep.X - isp.X);
                }
                else
                {
                    sx = Convert.ToInt32(iep.X);
                    w  = Convert.ToInt32(isp.X - iep.X);
                }
                if (isp.Y < iep.Y)
                {
                    sy = Convert.ToInt32(isp.Y);
                    h  = Convert.ToInt32(iep.Y - isp.Y);
                }
                else
                {
                    sy = Convert.ToInt32(iep.Y);
                    h  = Convert.ToInt32(isp.Y - iep.Y);
                }

                if (w == 0)
                {
                    w = 1;
                }
                if (h == 0)
                {
                    h = 1;
                }
                sb = null;
                sb = pt.getImageArea(si.Source as WriteableBitmap, sx, sy, w, h);
                ColorImg.Source = sb;
                Color c = pt.getAverageColor(sb);
                ShowColor(c);
            }
            sp = DrawGraphic.getImagePosition(sp, si);
        }