954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help with bitmap

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!

walid86
Junior Poster in Training
65 posts since Sep 2011
Reputation Points: 17
Solved Threads: 1
 

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

mazzica1
Junior Poster
147 posts since Oct 2011
Reputation Points: 9
Solved Threads: 27
 

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..

walid86
Junior Poster in Training
65 posts since Sep 2011
Reputation Points: 17
Solved Threads: 1
 

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

mazzica1
Junior Poster
147 posts since Oct 2011
Reputation Points: 9
Solved Threads: 27
 
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();
            }
walid86
Junior Poster in Training
65 posts since Sep 2011
Reputation Points: 17
Solved Threads: 1
 

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.

walid86
Junior Poster in Training
65 posts since Sep 2011
Reputation Points: 17
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: