Situation: i have a bitmap loadedImage1 which the user is able to resize, and move around inside picturebox1.

objective: this loadedImage1 is then to be added to a pdf document (which is working) but needs to be using the current size and location(as the user can move it around)

atm: the picture gets added, but the image is resized to fit the control, so the user's movement and resizing is ignored.

picturebox_double click looks like

// load image to image object
                loadedImage1 = Image.FromFile(openFD.FileName);
                // set initial rectangle bounds for image
                imageBounds1 = new System.Drawing.Rectangle(new Point(), loadedImage1.Size);
                // refresh the picture box to show new image
                pictureBox1.Refresh();
                pictureBox1.BackgroundImage = null;

mouse down and move are:

private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            // test if mouse click inside image bounds
            this.imageClicked = imageBounds1.Contains(e.Location);
            // capture relative position of mouse to Top,Left of image
            this.SizeOfImageOffset1 = (Size)imageBounds1.Location - (Size)e.Location;
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            // if image was clicked and mouse is captured
            if (imageClicked && pictureBox1.Capture)
            {
                Cursor.Current = Cursors.NoMove2D;
                // set new location for image based on relative mouse position
                imageBounds1.Location = (Point)(SizeOfImageOffset1 + (Size)e.Location);
                // force re-paint of picture box
                pictureBox1.Refresh();
            }
        }

and paint method is just

e.Graphics.DrawImage(loadedImage1, imageBounds1);

i just need to caputre loadedImage1 using its current x, y, width, height..

it should be simple, but i'm stuck...
i add it to the pdf using abcpdf 7, code:

units are in "mm".
myDoc.Rect.SetRect(10, 240, 92, 75);
            myDoc.AddImageBitmap((Bitmap)pictureBox2.BackgroundImage, true);

any tips would be great. thanks alot!

the question is not clear and you are using pictureBox1 in move and resize and pictureBox2 in save

i need to capture the contents of the picturebox.. after the user moves the bitmap, and reszes..

picturebox2 is a typo.... should be picturebox1

thanks..

when the user moves the image does this action crop the image ? if so you will nedd to create new image with the new size

when the user moves the image does this action crop the image ?

this is the code when the user moves the picture

// if image was clicked and mouse is captured
            if (imageClicked && pictureBox1.Capture)
            {
                Cursor.Current = Cursors.NoMove2D;
                // set new location for image based on relative mouse position
                imageBounds1.Location = (Point)(SizeOfImageOffset1 + (Size)e.Location);
                // force re-paint of picture box
                pictureBox1.Refresh();
            }

solved:

pictureboxX.drawtobitmap(bitmap, etc);

not perfect code, but it works, not sure if its the best option.. if any other methods, please share..

thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.