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.
Related
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.
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
Problem:
WebEye.WebCameraControl makes an excellent job to capture a picture (Bitmap) in a WinForm App.
When saving the image (Bitmap): image.Save("filename.jpg", ImageFormat.Jpeg) it will not add any
exif data, my need is just datetime.
There are many exampels how to read PropertyItems from an existing jpg, change attributes and save the image. But I cannot find any that adds new propertyItems to an "exif-empty" image.
There is image.SetPropertyItem(propItem) that looks promising but the propItem it self cannot be instantiated but retrieved from an image image.PropertyItems[x] Yes, I do miss something here but what?
Please save my day. This issue is driving me nutts.
Best regards
Stephan
My application works with large amount of images and I have to store some calculated info about each one. Frequently I need to get image's size for my calculations (sometimes without need to load original image).
What is better: each time to load needed Bitmap and to get its size, or at first get the size and store it in a Size object?
You said yourself "without need to load original image" - so sure get the compiled info for your bitmaps and store them. If you use a DB then you can for example store just your infos and the path to your bitmap. Only load big pictures if you really need them.
what i want to do is write an application in C# like "fraps" and other scren capture apps that when you press the "Print Screen" it saves the current screen as an image.
What i thought of is that
"i could create a background worker thread that checks the clipboard after x seconds and if there is an image, that is now in clipboard because of print screen click, it writes the clipboard contents to a jpeg or bitmap file" bu i lack the following knowledge
How will i know that there is an image in clipboard or some text or file
how to write that clipboard to an image file like how to convert that data into a JPEG (LZ-W format) or bitmap format etc.
Can anybody endow me with some knowledge or guide or help from C# coding prespective
The saving to a particular format is incredibly easy thanks to the Image class:
myImage.Save("someimage.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
As far as checking the clipboard, well you can do this, but i think you might run into issues that you won't know whether the image came from a Print-Screen, or from a Ctrl-c that the user did. However you can easily check the clipboard:
if (Clipboard.ContainsImage())
myImage = Clipboard.GetImage();