Get all points of Image to redraw c# - c#

Based on this post - save a graphics object to a varbinary db column c#, I created a control where I allow the user to draw on the control, and I save the drawn image to a database varbinary column. My problem is when I need to reload the signature and allow user to continue editing. I don't have all the points of the original image, so when I redraw, I only retain the user's edits.
Can somebody pls assist?

I figured it out, I was able to set the image loaded as the image of my picture box control, I used a graphics image from that loaded image. problem solved

Related

How to use textboxes on a specific location inside an image

I'm using Blazor-webassembly (PWA).
I have an image where the user needs to fill in form textboxes on specific places in the image.
I've thought about using SVG images to try to insert the textboxes inside of it. But since these are generated from a png, the path's aren't great and I can't put them on the exact locations inside the image.
Does anyone know another method to insert textboxes inside an image?

Save original image from PictureBox, not resized

Is it possible to save original image with original quality from PictureBox, not the stretched/resized one? I download byte array from a server and put it in PictureBox, I want user to be able to save the actual image, but it should be the original image (original quality and original size) I received from the HTTP server, not resized and reduced quality one that I show in a PictureBox. Is it possible or do I have to store the byte array I receive from server somewhere in order to achieve this?
Image property of the PictureBox contains the original image, while the control may paint the image as zoom/resized/stretched depending to its SizeMode. You can see the source code for the property here.
Just save the Image property and it will be the same image which you had read from database.
So calling pictureBox1.Image.Save will be enough.

Save Image in PictureBox with overlapping Controls

I am developing an application in which user can select an image in a picture box.
After that he can right click on the image and add a user control which will again display an Image along with some text. This user control can be added any number of times.
User can also re-position the user controls as per need.
All this functionality has been implemented and is working fine.
Now, the requirement is to save the Image along with the user control.
Above you can see the complete image which needs to be saved. Back image is the picture box image and the user control (small images with text).
When user will click on save button the image should get saved on his disk as a single image.
This is a windows application developed in C#.
I want to know that whether this functionality can be achieved or not. If yes, then please guide me in the right direction.
If you create a copy of the bitmap then with the Graphics.DrawImage() you can draw those images onto it. You need to calculate the position of those controls.
Look here for DrawImage: http://msdn.microsoft.com/en-us/library/42807xh1.aspx
example:
Bitmap copy = new Bitmap(OriginalBitmap);
Graphics g = Graphics.FromImage(copy);
g.DrawImage(arrowBitmap, new Point(..));
copy.Save(...);
A very simple and straight forward solution exists, has been thought of by Microsoft and includes these steps:
Instead of PictureBox use a Panel and instead of using the Image property of the PictureBox use the BackgroundImage property of the Panel
note: By using also the BackgroundImageLayout property you can quite easily instruct the Panel to stretch, center or zoom the image (I'm presuming the default value which is tile is not a good option in your case)
Instead of placing the other user controls at higher Z order but alongside the previous PictureBox place them inside the Panel
Use the Control.DrawToBitmap method like so:
private void button1_Click(object sender, EventArgs e) {
var bmp = new Bitmap(this.panel1.Width, this.panel1.Height);
this.panel1.DrawToBitmap(bmp, new Rectangle(Point.Empty, bmp.Size));
bmp.Save(#"D:\test.png", ImageFormat.Png);
}
That will result in your controls begin rendered along with the picture:
Furthermore, and if your scenario allows it, you could simply use the DrawToBitmap method with any control which contains all of the actors you wish to render, for instance the actual Form.

Re-encoding of Jpeg Image in binary column when saving

I know there are similar questions, but I have a question concerning the storage of images in a binary-column.
I have a small windows forms app that loads an image into a picturebox control from a sql compact db using Linq2SQL. The user can drag any image (jpg,bmp,gif) on a picturebox. On the DragDrop-Event the image is loaded into the picturebox.
When I save the record following code is executed to store the image of the picturebox control:
MemoryStream imgStream = new MemoryStream();
pictureBox1.Image.Save(imgStream, System.Drawing.Imaging.ImageFormat.Jpeg);
myTable.MyImage = imgStream.ToArray();
I have checked the size of the byte array and it didn't change after saving the record.
Is the image re-encoded every time the Save-Method is called? It would be maybe then better to check if the image has changed at all.
JPEG images are decoded as a function of their being displayed by .NET (or really just about anything). So, if you pull a JPEG out as a binary, put it in a PictureBox (which will convert it to a raster format to display), then take that now-uncompressed raster Image and recompress it, you MAY end up making changes to that image.
I would keep the original bytestream for the displayed Image somewhere behind the scenes, and write that back to the DB when the user saves the data. This will not only help preserve the integrity of the image, it will boost performance by reducing the need to recompress the image every time.
If this code is called when you call Save then yes, the PictureBox will "export" itself as a JPEG every time. Are you noticing a performance issue because of this? If you want to avoid it, set a flag on application load and when the drag/drop event occurs raise the flag signaling that the Save method should update the image data.

c# picturebox bitmaps

I have a picturebox that upon request, I save the current display to a bitmap.
My question is, how do I then load that same bitmap to the picturebox?
Thanks.
EDIT:
The only relevant code is:
pictureBox1.DrawToBitmap(test1,pictureBox1.ClientRectangle);
The picture box contains graphics that I have written 'freehand' using the mouse. So you can use the mouse to write directly onto the screen when the left mouse is pressed.
You can assign any image to the picture box that you want during run-time. Just set the Image property of the picture box to the picture you want to be displayed.
For example, to display an image in a picture box from a file on your hard drive, you could use something like:
myPicBox.Image = Image.FromFile("C:\savedimage.bmp");
Or, your edit suggests that you have a bitmap object in memory that you want to display in the picture box. In that case, it's a simple matter of assigning that bitmap object to the Image property:
myPicBox.Image = test1; //(where test1 is your bitmap object in memory)
Edit: Just in case you want to save the bitmap object that you created in memory to disk so that you can reload and use it later, check out the Save method of the Bitmap object:
test1.Save("C:\savedimage.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
If I'm not mistaken, the picturebox should have an Image property that you can simply use to assign the Bitmap to.

Categories