How do I display tiff files on Silverlight? - c#

How do I display tiff files on a Silverlight application? I can display any image format except tiff, can anyone help me? Thanks.

I was successful displaying TIFFs in Silverlight. It's easy to port the free LibTiff.NET library to Silverlight, just 3-4 minor tweaks required.
The library itself is quite legacy-like and raw to use and one still needs to have some knowledge about the inner workings of the TIFF format in order to be able to extract the image data the way one needs it.
But it's doable and the bits and pieces can then be chiseled into a WriteableBitmap.

Why don't you try TiffLight? It is a Silverlight control that allows native display of Tiff files in Silverlight.

A Tiff file is a multi-page format so rendering it is not as simple as a png, gif or bmp.
You have of course already found this via a web search but it'll cost you.

Silverlight 2.0 doesn't support tiff images according to this.
However, in the article I believe it explains a way to convert the tiff image to a jpeg or a png (which is supported by Silverlight). However, you'll have to do this processing on the server-side.

I would use an HttpHandler that converts the Tiff using the TiffBitmapDecoder and PngBitmapEncoder classes.
Alternatively, if you can decode the Tiff images in Silverlight, you can display them using a WriteableBitmap.

Related

TIFF file does not show on picturebox

I'm trying to show TIFF files on a picturebox in C#. My code is here:
pictureBox1.Image = Image.FromFile("someName.tif");
This code is working fine, but some TIFF file isn't displaying on the picturebox (the TIFF file isn't broken). What is wrong?
This TIFF file contains one color image compressed using JPEG 4:4:4.
Although Microsoft functions can handle some sub-types of TIFF, including some JPEG compressed varieties, this particular file uses a flavor of JPEG compression known as "old style". It appears Microsoft functions do not support this flavor.
If you need to load such files in your code, you might have to use a dedicated imaging library.

how to upload bmp bitmap image in silverlight?

I am writing a code in silverlight. I want to upload images on my silverlight application. Please help me how do I upload bitmap images and show them on interface. If I am wrong please sort it out.thanks
Silverlight only natively supports .jpg and .png files. You will need a third party library to decode (or convert) bmp files for use by Silverlight.
You could potentially show them in a web browser control within Silverlight, but MS chose PNG and JPG for a reason, so why add complexity.I'd say convert them on the server after upload using one of many third party libraries available.
Can you provide some more detail? Do you want to upload this to a directory on your site, store it within a DB or just retain it for the session and then dispose of the image?
There are a number of examples such as Silverlight File Upload on codeplex. or File Uploader. If you are looking to upload to just a directory on your website you may want to look at this example as well.
Aside from those starting points you need to provide some more detail as where you are having issues.

How to open and render SVG files in .NET environment?

Are there any relatively easy ways to deal with SVG images in .NET?
How to extract all graphic primitives from file.
How to render a SVG file to memory buffer (with transparency)
P.S.
I'm using SFML as a graphic outputting engine.
please see Converting SVG to PNG using C# - there are two options to deal with SVG from .NET...
Another option is http://www.codeproject.com/KB/WPF/SharpVectors.aspx

To load .tiff file in C#

I have to load .tiff file
I did with both Image.FromFile() and Bitmap.FromFile()
But they are throwing OutOfMemoryException
Any solution for how to load this?
I assume that the TIFF file you are trying to load uses a compression that is not compatible with .Net. Namely the JPEG compression is not supported by .Net.
I suggest you try LibTiff.Net (though I cannot tell for sure if it will work):
I use ImageGlue. It can convert a lot more then just tiff.
There is a project on codeproject: "How to Load/Display images with C#".
Take a look at it
There is a possibility that this issue occurred due to multiple image tiff file. In this case, you have to extract individual image files from the source tiff file and then view those frame by frame. Here is a sample code.
http://www.c-sharpcorner.com/Blogs/10924/how-to-save-split-merge-and-view-multipage-tiff-image.aspx

How to create an image from a raw data of DICOM image

I have a raw pixel data in a byte[] from a DICOM image.
Now I would like to convert this byte[] to an Image object.
I tried:
Image img = Image.FromStream(new MemoryStream(byteArray));
but this is not working for me. What else should I be using ?
One thing to be aware of is that a dicom "image" is not necessarily just image data. The dicom file format contains much more than raw image data. This may be where you're getting hung up. Consider checking out the dicom file standard which you should be able to find linked on the wikipedia article for dicom. This should help you figure out how to parse out the information you're actually interested in.
You have to do the following
Identify the PIXEL DATA tag from the file. You may use FileStream to read byte by byte.
Read the pixel data
Convert it to RGB
Create a BitMap object from the RGB
Use Graphics class to draw the BitMap on a panel.
The pixel data usually (if not always) ends up at the end of the DICOM data. If you can figure out width, height, stride and color depth, it should be doable to skip to the (7FE0,0010) data element value and just grab the succeeding bytes. This is the trick that most normal image viewers use when they show DICOM images.
There is a C# library called EvilDicom (http://rexcardan.com/evildicom/) that can be used to pull the image out of a DICOM file. It has a tutorial on how to do it on the website.
You should use GDCM.
Grassroots DiCoM is a C++ library for DICOM medical files. It is automatically wrapped to python/C#/Java (using swig). It supports RAW, JPEG 8/12/16bits (lossy/lossless), JPEG 2000, JPEG-LS, RLE and deflated (zlib).
It is portable and is known to run on most system (Win32, linux, MacOSX).
http://gdcm.sourceforge.net/wiki/index.php/GDCM_Release_2.4
See for example:
http://gdcm.sourceforge.net/html/DecompressImage_8cs-example.html
Are you working with a pure standard DICOM File? I've been maintainning a DICOM parser for over a two years and I came across some realy strange DICOM files that didn't completely fulfill the standard (companies implementing their "own" twisted standard DICOM files) . flush you byte array into a file and test whether your image viewer(irfanview, picassa or whatever) can show it. If your code is working with a normal JPEG stream then from my experience , 99.9999% chance that this simply because the file voilate the standard in some strange way ( and believe me , medical companies does that a lot)
Also note that DICOM standard support several variants of the JPEG standard . could be that the Bitmap class doesn't support the data you get from the DICOM file. Can you please write down the transfer syntax?
You are welcome to send me the file (if it's not big) yossi1981#gmail.com , I can check it out , There was a time I've been hex-editing DICOM file for a half a year.
DICOM is a ridiculous specification and I sincerely hope it gets overhauled in the near future. That said Offis has a software suite "DCMTK" which is fairly good at converting dicoms with the various popular encodings. Just trying to skip ahead in the file x-bytes will probably be fine for a single file but if you have a volume or several volumes a more robust strategy is in order. I used DCMTK's conversion code and just grabbed the image bits before they went into a pnm. The file you'll be looking for in DCMTK is dcm2pnm or possibly dcmj2pnm depending on the encoding scheme.
I had a problem with the scale window that I fixed with one of the runtime flags. DCMTK is open source and comes with fairly simple build instructions.

Categories