예제 #1
0
    public void Dragging(Ray r)
    {
        if (cropping)
        {
            RaycastHit hit;

            LayerMask mask = LayerMask.GetMask("EditCanvas");
            //Debug.DrawRay(r.origin, r.direction * 100, Color.green, 3);
            if (Physics.Raycast(r.origin, r.direction, out hit, mask))
            {
                //hit occurred
                Texture2D image        = cs.GetImage();
                Vector2   textureCoord = Vector2.Scale(hit.textureCoord, new Vector2(image.width, image.height));

                //GameObject cube = (useCube1) ? cube1 : cube2;
                if (useCube1)
                {
                    coords1 = textureCoord;
                }
                else
                {
                    coords2 = textureCoord;
                }

                CropRect cropRect = GetCropRect();
                Line.transform.localPosition = new Vector3((float)cropRect.x / image.width * -10 + 5, 0.01f, (float)cropRect.y / image.height * -10 + 5);
                Line.transform.localScale    = new Vector3(-(float)cropRect.width / image.width * 10, 0, -(float)cropRect.height / image.height * 10);
            }
        }
    }
예제 #2
0
        public FrmMain()
        {
            InitializeComponent();

            this.Icon           = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            currentshape        = ShapesTypes.ShapeTypes.CropRect;
            this.DoubleBuffered = true;

            ContextMenuSelectColor.ColorScheme   = ComponentFactory.Krypton.Toolkit.ColorScheme.OfficeStandard;
            ContextMenuSelectColor.SelectedColor = Color.Red;
            BtnColor.ForeColor = SelectedColor;

            OriginalScreenImage = AssistOperation.CaptureScreen();

            cropRect = new CropRect(new Rectangle(-5, -5, 1, 1));
            cropRect.SetForm(this);

            cropRect.Visible = true;

            cropRect.RectMoved += CropRect_RectMoved;

            this.BackgroundImage       = AssistOperation.FadeImage(OriginalScreenImage);
            this.BackgroundImageLayout = ImageLayout.Center;

            undoactions = new UndoRedo();
        }
예제 #3
0
    public static Image CaptureResult(Control ctrl, CropRect croprect)
    {
        Rectangle bounds = croprect.rect;
        Point     pt     = ctrl.PointToScreen(bounds.Location);
        Bitmap    bitmap = new Bitmap(bounds.Width, bounds.Height);

        using (Graphics graph = Graphics.FromImage(bitmap))
        {
            graph.CopyFromScreen(new Point(croprect.rect.X - ctrl.Location.X, croprect.rect.Y - ctrl.Location.Y), Point.Empty, bounds.Size);
        }

        return(bitmap);
    }
예제 #4
0
    CropRect GetCropRect()
    {
        CropRect  res   = new CropRect();
        Texture2D image = cs.GetImage();

        int x1 = Mathf.Clamp(Mathf.RoundToInt(coords1.x), 0, image.width - 1);
        int x2 = Mathf.Clamp(Mathf.RoundToInt(coords2.x), 0, image.width - 1);
        int y1 = Mathf.Clamp(Mathf.RoundToInt(coords1.y), 0, image.height - 1);
        int y2 = Mathf.Clamp(Mathf.RoundToInt(coords2.y), 0, image.height - 1);

        res.x = Mathf.Min(x1, x2);
        res.y = Mathf.Min(y1, y2);

        res.width  = Mathf.Abs(x1 - x2 + 1);
        res.height = Mathf.Abs(y1 - y2 + 1);

        return(res);
    }
예제 #5
0
    public static Image CropImage(Image OriginalScreenImage, CropRect croprect, Form frmMain)
    {
        Bitmap OriginalImage = new Bitmap(OriginalScreenImage, frmMain.Width, frmMain.Height);

        Bitmap _img = new Bitmap(croprect.rect.Width, croprect.rect.Height);

        using (Graphics graph = Graphics.FromImage(_img))
        {
            graph.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            graph.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            graph.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            graph.DrawImage(OriginalImage, 0, 0, croprect.rect, GraphicsUnit.Pixel);
        }

        OriginalImage.Dispose();

        return(_img);
    }
예제 #6
0
    public void Apply()
    {
        Debug.Log("applying crop");
        CropRect cropRect = GetCropRect();

        Texture2D image = cs.GetImage();

        Color[] pixel = image.GetPixels(Mathf.RoundToInt(cropRect.x), cropRect.y, cropRect.width, cropRect.height, 0);

        Texture2D newtex = new Texture2D(cropRect.width, cropRect.height);

        newtex.SetPixels(pixel);
        newtex.Apply();

        Debug.Log("here");
        cs.SetImage(newtex);
        Cancel();
        Debug.Log("done applying");
    }
        public override async Task <string> CropAsync(string source, CropRect cropRect)
        {
            var image = await LoadAsync(source);

            var d = cropRect.Destination;

            return(await Task.Run <string>(() =>
            {
                string name = System.IO.Path.GetFileNameWithoutExtension(source);
                string ext = System.IO.Path.GetExtension(source);
                var tempFile = Java.IO.File.CreateTempFile(name, ext);
                image = Bitmap.CreateBitmap(image, (int)d.Left, (int)d.Top, (int)d.Width, (int)d.Height);
                tempFile.DeleteOnExit();
                using (var s = System.IO.File.OpenWrite(tempFile.CanonicalPath)) {
                    image.Compress(Bitmap.CompressFormat.Png, 0, s);
                }
                return tempFile.CanonicalPath;
            }));
        }
예제 #8
0
        public override async Task <string> CropAsync(string source, CropRect cropRect)
        {
            var image = await LoadAsync(source);

            var d = cropRect.Destination;

            return(await Task.Run <string>(async() =>
            {
                string name = System.IO.Path.GetFileNameWithoutExtension(source);
                string ext = System.IO.Path.GetExtension(source);
                var tempFile = $"{System.IO.Path.GetTempPath()}/{name}-{(Guid.NewGuid().ToString().Trim('{', '}'))}{ext}";
                var r = new CGRect(d.Left, d.Top, d.Width, d.Height);
                var cgi = image.CGImage.WithImageInRect(r);
                image = new UIImage(cgi);
                using (var s = System.IO.File.OpenWrite(tempFile))
                {
                    var iss = image.AsPNG().AsStream();
                    await iss.CopyToAsync(s);
                }
                return tempFile;
            }));
        }
예제 #9
0
 public abstract Task <string> CropAsync(string source, CropRect cropRect);