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

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

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.

Trying to display a portion of a large (2 GB) Tiff image in a Winform app

Is this possible or do I have to use WPF. I am new to Winforms and have created a couple simple applications, now I need to read a TIFF file and then display a subsection of it...
I tried doing something like this:
Graphics g = e.Graphics;
Bitmap b = new Bitmap(Image.FromFile(#"W:\ILHSR_Merged_2011\compressed\overviews\ILHSR11_0405-101-1.tif"));
g.DrawImage(b, 10, 10, 350, 300);
But I get out of memory exceptions. Can someone point me to some readin, or is this simply something that should be developed in WPF.
I think you need to implement you own TIFF loader using libTiff.
TIFF image format allow to store image data in tiles. LibTiff allows you to load single tiles: in this way you can display only portion of the image (without decoding the entire TIFF!, that can have prohibitive sizes).
Unfortunately, I don't think that .NET imaging supports that TIFF feature. My suggestion is to wrap libTiff in a library written in C++/CLI, and integrate it in your application.
(Due comment: if some existing library has already wrapped libTiff, and its interface match nicely with your application, even the better)
If you need to display parts, consider using tiled Tif files, and possibly even image pyramids (see TIF pyramid for background info on how to create/use them) tif files. All of these can be read with LibTiff and LibTiff.NET
Of course this depends on how often you need to do it. My experience is that very large bitmaps cannot be displayed properly using 32bit windows versions, unless the file itself is tiled. I have made a wrapper for LibTiff.NET, which allows Tile access also for non tiled (uncompressed, or line based) files. Of course, access is slower then; you'd need to read the entire rows which are on display. Still response time was reasonable for gigapixel images.
BitMiracle LibTiff.NET mentioned in previous post/comment works great: see How to implement pan/zoom on gigapixel bitmaps? and How to implement pan/zoom on gigapixel bitmaps?; it is a native c# implementation of LibTiff, which I found easier to handle than a wrapper class (because there is no unmanaged memory blocks to take care of in c# app).
[Edit]Added link to TIF pyramid image documentation[/Edit]

How to load cmyk image with c++ or c# and to change cmyk values of every pixel?

For a whole month I've been trying to find out how to load a cmyk image (8-bit tiff) and do a UCA, UCR, GCR transformations.
I know the formulas for this transformations, but I have a problem to load an cmyk image with C++ or C#.
My plan is to manipulate the image pixel by pixel and change every value C, M, Y, K of that pixel, and finally save changed image as 8-bit tiff cmyk image. So basically I want to run through each pixel, make change to cmyk values, and save the image.
I have difficulties to find and install such a library for C# or C++, and I'm using Visual Studio Express 2010 for both.
What libraries can I use to load these images?
libtiff will let you manipulate TIFF files. See also this answer on building libtiff using Visual Studio.
You'll need to read the image row by row using TIFFReadScanline to avoid conversion to RGB by the library. The open source tifftopnm utility does this; its source is here - it uses pick_cmyk_pixel to convert the data to RGB after obtaining it, but naturally you can just substitute your own logic instead.
EMGU is a c# wrapper for opencv (c++) either of these will allow Tiff files to be easily used and manipulated. They will allow you to access pixels more readily and uses highly optimised code. Since these are a dedicated image processing libraries they will allow you to do more with your image without having to worry about RGB conversion or reading the file in etc.
Hope they help,
Cheers
Chris

How do I display tiff files on Silverlight?

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.

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