Screen Capture Feature Overrides - c#

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

Related

What type of image filtering/processing do mobile PDF scanners use to convert a captured image into a monochrome/black and white image?

I am trying to implement my own monochrome/black and white filter in C# to scan text documents. My approach is to apply a threshold filter on the captured image. However, I often run into the problem that the varying brightness on the image causes a ''shadowing effect'' on the processed image. Refer to the link below (it is pretty blurry but it should suffice). The image to the far left is the original image. When I apply my threshold filter, I get the same result as the image in the middle; some of the text becomes unreadable because the brightness of the image varies, so some portions become really black or really white. However, with the right filter, you can obtain the processed image to the right where everything looks crystal clear.
https://www.google.dk/search?q=monochrome+image+processing&espv=2&biw=1706&bih=859&source=lnms&tbm=isch&sa=X&ved=0ahUKEwir8vXlhIzPAhUFiywKHeSBC1wQ_AUIBigB#imgrc=4UTzoIpyqTkwrM%3A
I would like to know what the process is to obtain the image to the far right. Another example can be seen in the image below. It shows a sample mobile PDF scanner in use. Scanning the image results in a very nice black and white image, where the text can be easily read and no ''shadowing'' occurs on the image. Does anyone know what this process is or what it is called? It is very often used in mobile PDF scanning applications. Thank you in advance.
EDIT: The filter is called ''Adaptive Thresholding''. You can use the BradleyLocalThresholding class to implement the filter, or you can write it yourself (which is what I did). Please refer to my response to the comment by Yves Daoust down below.
You need two ingredients.
One is "background reconstruction", i.e. retrieving the intensity of the white sheet "under the characters", for instance by morphological opening.
The other is "shading correction", i.e. compensating the unevenness of the background illumination by comparing to the reconstructed background, for instance by subtraction.
This will "flatten" the image, making it perfectly amenable to global thresholding.
A simple method is to convert the image to grayscale and then convert it to B/W using an error diffusion algorithm such as Floyd–Steinberg dithering.

Adding EXIF DateTime to a jpeg image

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

Put .Gif Image from Clipboard to PictureBox

I want to copy gif image from Browser and paste to PictureBox
Image cImage = Clipboard.GetImage();
pictureBox1.Image = (Image)cImage;
This put image, but its not animated.
The image on the clipboard isn't a GIF, it's a Bitmap or DIB (or both). Those are the formats that you would see, if you used the old XP Clipboard Viewer (clipbrd.exe), or if you enumerated the available clipboard formats within your program.
See the list of standard clipboard formats: http://msdn.microsoft.com/en-us/library/windows/desktop/ff729168(v=vs.85).aspx
GIF is not one of them.
Also, there is no JPG or PNG. When you copy those images, they're placed onto the clipboard as CF_BITMAP and/or CF_DIB. Basically, Bitmap is the universal image format that everything converts to/from.
As an alternative, you MAY be able to get CF_HTML from the clipboard, figure out where the image is, and then fetch it from the server (or maybe the browser cache), preserving the original GIF information.

Replace text in PDF

I'm trying to replace a section of a PDF with different text. From research on all major PDF libraries for .NET, it seems this is complicated and not a trivial task. I think it may be easier to convert the PDF to an image, replace the text (always in the same place), then convert it back to a PDF (or leave it as an image if converting back isn't possible). Is it possible to extract an image from a PDF page with .NET?
If your text is in a known location, you can simply cover it with a rectangle filled with the background color, and then draw your text over top.
Note that the text will still be there, it simply won't be visible. Someone selecting text will still pick up the old stuff. If that's acceptable, it's quite trivial.
If the PDF was created from image, you can import it into Photoshop to edit it as an graphic. Or you can use screenshot program like "Snagit" to capture pdf page as image and use snagit's editor to erase old text and replace new one.
But this method may bring you problem is that the new added text may not the same font as text around it. Personally, I use pdf editor to replace text in pdf since the added text will be automatically fit with the original font and size.

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.

Categories