.NET Tiff Issues C# - c#

I'm having issues with TIFFs
Here is what I have to do, we have tiff images saved into the database, these images are CCITT4 compressed with a number of required tags, these include:
RowsPerStrip must be the ImageLength
Photometric Interpreation must be MinIsWhite
Multi-strip image format is not allowed
My problem is, I'm using the built in System.Drawing.Bitmap/Image objects, which happen to change the values of these when I put it into the object, I've tested this by saving the byte[] to a tiff directly from the database, checked the tags, they are fine.. but when i put the bytes into an Image object then save to file, they are modified.
To make things worse, I'm needing to add a text to the image before saving it.
So I need a component that will allow me more control with TIFF (and they must be tiff), and be able to add text to an image or be able to use the Graphics object.
I've tried using LibTiff but I have yet to see any examples on how to use this component,
any suggestions?

You can use our free and open-source LibTiff.Net library for this. It is freely available for all uses under a BSD license. The just released version 2.0 contains good documentation and number of samples.
There are samples that show how to convert any non-tiled TIFF image to the TIFF image which have all data written in a single strip and how to convert a System.Drawing.Bitmap to 1-bit CCITT single strip TIFF image.

I have never used the built int System.Drawing.Bitmap objects to do this. I personally use LeadTools, but it isn't free. It is however a robust and fairly straightforward API. I primarily use it for GEOTiff which contain specific data tags for image location data.
There is a 60 day evaluation if you would like to try it out.

I use FreeImage. There's a C# .NET wrapper available too.

The IEvolution component set from HiComponents is now totally free (no source) - http://www.hicomponents.com. A very powerful .NET imaging toolkit.

Related

Remove all metadata from common image formats?

I'm writing a service for a project that's going to handle our image processing. One such process is supposed to strip all metadata from the byte[] provided and return the same image as a byte[].
The method I'm currently working on involves always converting the image to a Bitmap, then converting it back to the original format and returning the data from a MemoryStream.
I haven't been able to test it yet but something tells me I'm going to experience some quality loss.
How can I remove all metadata from any image with a common format?
(bmp, gif, png, jpg, icon, tiff)
Not sure how I can narrow that down any further. Would be nice if I got some feedback regarding the downvotes.
For the lossless formats (except JPEG), your idea of loading it as a bitmap and re-saving is fine. Not sure if .NET natively supports TIFFs (I doubt it does).
For JPEGs, as you suggested there may be quality loss if you're re-compressing the file after decompressing it. For that, you might try the ExifLibrary and see if that has anything. If not, there are command line tools (like ImageMagick) that can strip metadata. (If you use ImageMagick, you're all set, since it supports all of your required formats. The command you want is convert -strip.)
For TIFFs, .NET has built-in TiffBitmapDecoder and ...Encoder classes you might be able to use; see here.
In short, using an external tool like ImageMagick is definitely the easiest solution. If you can't use an external tool, you're almost certainly going to need to special-case the formats that .NET doesn't support natively (and the lossy JPEG).
EDIT: I just read that ImageMagick doesn't do lossless stripping with JPEGs, sorry. I guess using the library I linked above, or some other JPEG library, is the best I can think of.

bitmaps to avi file c# .Net

I have a list of Bitmaps, how can I convert it to avi file using c#.net. Or how can we convert a set of images to video file ?
I do not need AVI to "Set of images", but I need "Set of Images" to AVI.
i used avifile wrapper in the past, work nicely
I think you need to use third party libraries
There is AVI File Wrapper or you can use ffmpeg in .NET.
Old question, but I have two tips to achieve it. We're now 2013, but all answers are good from 2004 to 2013. These answers are useful as it seems programmers rarely take the time to work on new encoders solution, and we often rely on the same old DLL and wrappers.
Images to MPEG-1
Based on this code, http://www.codeproject.com/Articles/5834/A-C-MPEG1-Image-Compression-Class, you can write a C# Images to MPEG-1 class compatible on any platform using C#.
Images to AVI
Convert just an image with 24 bits color (try to use a gradient generator to have the maximum number of colors) to a full frame AVI using ffmpeg. Take an hexadecimal editor, check how the header of the AVI is, and how the single image has been placed in the AVI. Now do it with two images. Check the header. Refer to the specification to know which value use in the header. You'll see you can easily build a Images to AVI from scratch without any wrapper, and use it on any platform.
Both are codes from scratch.
You can check out a simple library for writing AVI files that I've coded to use in my projects.
https://sharpavi.codeplex.com/
The sources include a sample screencast app which can be easily adapted to get the bitmaps from files if you need it.

Decoding a PCX image in c# to display as bitmap

I have been trying to create a decoder that will stream through a pcx file and display it on screen as a bitmap. I have managed to get the information from the image header by using a binary reader, but I have now reached the part that seems to take the least amount of code, yet is also the hardest: creating an array of pixels.
I understand that i may need to add two embeddded for loops to process the data. I have looked at some C and C++ examples, but struggle to understand them. I also need to get the array to display it. if you need more code then I will share it.
I have searched far and wide and read the spec, but I don't know how to approach this. If anyone could help me, I would be very grateful.
Regards.
The .NET does not support PCX images natively, you have two choices. Read the specification and decode the image by yourself or use some library.
As suggested on bytes.com you can use Dot Net Fireball (a Free Image wrapper) and load the image like this:
Fireball.Drawing.FreeImage freeImage = new FreeImage(#"c:\test.pcx");
Image image = freeImage.GetBitmap();
http://magick.codeplex.com/
a nice wrapper working with http://imagemagick.codeplex.com/
easy to setup and get going, see samples at the bottom of the page here:
http://magick.codeplex.com/documentation

How to load EPS files and draw them using WinForms

Is it possible to load and display EPS file using plain WinForms GDI+? If not, is there a free library to help out?
I seem to remember that Windows GDI supported EPS files, but after Googling around a bit, I am starting to doubt that memory.
All I want to do is load the file and draw it using a Graphics context.
I am aware that I can just use any program to convert the file to PNG or something and render it that way, but because I am trying to render at multiple resolutions, I would prefer to keep the vector data in the EPS file.
Thanks!
All the free or open source libraries I know that can convert EPS to other vector or raster format are all based on Ghostscript. You can invoke ghostscript directly, with wrapper provided or alternatively look at imagemagick. It is a very popular library for manipulating image graphics and has been around for a long time. It also internally relies on Ghostscript for handling EPS format. There is a .NET wrapper for it that you can find at http://imagemagick.codeplex.com/. You can read a bit about its background here too http://www.codeproject.com/KB/dotnet/ImageMagick_in_VBNET.aspx. There is also pstoedit that is also based on ghostscript to read EPS and allow export to format like WMF. You will need to the call to pstoedit API using interop in .NET
Besides Ghostscript there are several commercial products that I known of like ImageGear and LeadTools which will let you take EPS to almost any other kind of graphic formats.
You can use GhostScript to produce images from an EPS. Once you have an image you can then display that within your application.
In your question you indicated you want the output in a vector format which would preclude bitmaps, jpeg etc. Here are a couple of ways of getting a XAML file which is a vector file with extensive support by Microsoft.
Microsoft Expression Blend 3 and Design 3 can both open .ai (eps) files and convert them to vector formats, design and XAML respectively, so it is definitely possible.
I know it is relatively easy to automate most Microsoft Office applications like Word and Excel, but I have not seen any documented com inter-op assemblies for these Expression products.
Perhaps you can use the converters that are part of Expression in an undocumented way?
If that doesn't work here is plan B:
Here is a free converter that will convert .ai (eps) files to XAML. To use it you need Adobe Illustrator however.

Convert multiple byte[] to multipage tiff equivalent of Image.SaveAdd without GDI+

I am working on a system that stores many images in a database as byte[]. Each byte[] is a multi page tiff already, but I have a need to retrieve the images, converting them all to one multi page tiff. The system was previously using the System.Drawing.Image classes, with Save and SaveAdd - this was nice in that it saves the file progressively, and therefore memory usage was minimal, however GDI+ concurrency issues were encountered - this is running on a back end in COM+.
The methods were converted to use the System.Windows.Media.Imaging classes, TiffBitmapDecoder and TiffBitmapEncoder, with a bit of massaging in between. This resolved the concurrency issue, but I am struggling to find a way to save the image progressively (i.e. frame by frame) to limit memory usage, and therefore the size of images that can be manipulated is much lower (i.e. I created a test 1.2GB image using the GDI+ classes, and could have gone on, but could only create a ~600MB file using the other method).
Is there any way to progressively save a multi page tiff image to avoid memory issues? If Save is called on the TiffBitmapEncoder more than once an error is thrown.
I think I would use the standard .NET way to decode the tiff images and write my own tiff encoder that can write progressively to disk. The tiff format specifications are public.
Decoding a tiff is not that easy, that's why I would use the TiffBitmapDecoder for this. Encoding is is easier, so I think it is doable to write an encoder that you can feed with separate frames and that is writing the necessary data progressively to disk. You'll probably have to update the header of the resulting tiff once you are ready to update the IFD (Image File Directory) entry.
Good luck!
I've done this via LibTIFF.NET I can handle multi-gigabyte images this way with no pain. See my question at
Using LibTIFF from c# to access tiled tiff images
Although I use it for tiled access, the memory issues are similar. LibTIFF allows full access to all TIFF functions, so files can be read and stored in a directory-like manner.
The other thing worth noting is the differences between GDI on different windows versions. See GDI .NET exceptions.

Categories

Resources