Adding EXIF DateTime to a jpeg image - c#

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

Related

PictureBox that takes into Account EXIF Orientation Tag and Final Image Rotation

The Picturebox control in c# does not take into account the EXIF Orientation tag for images.So the images appear in the wrong orientation.I intent to solve this problem by reading the EXIF data and manually rotating the Image.But processing the image with exif orientation tag is a problem.Since the user may choose any output format and if i assume right only JPEG and TIF support EXIF.So the final processed image should be manually rotated rather than adding the EXIF Tag.
Is my assumption correct?
Your assumption is mostly correct.
Orientation tags are supported in JFIF (plain JPEG), TIFF (countless sub-types) and the 2 types of Exif (JPEG-compressed and single-page uncompressed TIFF). Almost all other common image formats do not support it, but that depends on how you define common.
This post discusses some ways developers can handle similar situations.
Although the discussion is about LEADTOOLS, the design logic behind the 3 options discussed is valid regardless of the classes or functions you use to handle your images.

Format for saving to disk a canvas containing shapes, images, and text

This is a WPF newbie's request for suggestions ( so there is no code here )
In my application, I present to the user a canvas onto which he can drag drop shapes, textboxes and images. Kind of like Visio. Now the user wants to save what he created to a file. How do I go about doing that, which classes do I use? And what data format choices do I have? What if I want to save it in XML format?
Most grateful for advice and pointers
You can convert it to a bitmap and then save the bitmap to file. To read it again just use bitmap BMP = bitmap.FromFile(file);
Update..
If you want to save all the changes that have been made you then need to create a file format probably something like:
Circle 1, 15 ,25, 100,250,10
Where the format is:
Shape size, positionx, positiony, rgb value

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.

How to change picture file dimension in C#?

I am working a mvc web app. I upload a image to use it as system logo. Now if I select image and upload it, it can be replaced easily until image file is not of large dimesion. For file with large dimension i need to reduce its size to some smaller size to make it look like a system logo. Preferable size for my logo is 100x75. How can I reduce the file dimesion?
THanks,
kapil
try this.
I found it in the msdn, and it works.
Bitmap map = new Bitmap(Image.FromFile("F:\\1.jpg"), new Size(20, 20));
map.Save("F:\\5.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
You can use the classes that are in the System.Drawing namespace.
See this tutorial for details.

Screen Capture Feature Overrides

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();

Categories