|
 |
|
|
When I tried
pictureBox1.Image = Image.FromFile("aGeoTiffFile.tif");
I got an error: System.Exception: A Graphics object cannot be created from an image that has an indexed pixel format.
Can I load geoTiff file and access its meta info with C#?
Frank
|
| Sign In·View Thread·PermaLink | 1.00/5 (1 vote) |
|
|
|
 |
|
|
Hmm...if I recall correctly, GeoTIFF images are TIFF 6.0 compliant. Also, I know for a fact that System.Drawing.Image can handle indexed pixel formats.
Have you tried reading the IFD(s) yourself?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
I use JoinTiffImages function to merge tif. but can't merge MultiFrame tif. ex:A.tif merge B.tif,A.tif have Page2,B.tif also too. user JoinTiffImages function merge A and B to New tif is C.tif. but C.tif only A.tif Page1 and B.tif Page1,A Page2 and B Page2 not join. have anybody can tell my why? Please ! thanks
Jackie Lin
|
| Sign In·View Thread·PermaLink | 2.00/5 (2 votes) |
|
|
|
 |
|
|
 |
|
|
The issue with the Join methods is that they are only saving the active frame of each image (page 1 by default)
To resolve this issue, each image must have its frames looped through and saved to the stream using the following methods:
public static int GetPageCount(ref Image img) { if (img != null) { Guid objGuid = img.FrameDimensionsList(0); FrameDimension objDimension = new FrameDimension(objGuid); return img.GetFrameCount(objDimension); } else { //If the image is nothing, return a count of 0 return 0; } }
public static void SelectFrame(ref Image img, int index) { if (img != null) { Guid objGuid = img.FrameDimensionsList(0); FrameDimension objDimension = new FrameDimension(objGuid); if (index < img.GetFrameCount(objDimension) && index >= 0) { img.SelectActiveFrame(objDimension, index); } } }
In place of the current .Save lines of code, use the above methods like so:
... Bitmap bm=(Bitmap)Image.FromFile(strImageFile); for (int j = 0; j <= GetPageCount(bm) - 1; j++) { SelectFrame(bm, j); pages.SaveAdd(bm, ep); } ...
Be sure to also do this for the "frame==0" case to ensure the first image is saved fully to the result image - but use SaveAdd on pages 2 - x!
There is a more elegant solution to this, but this will get you by for now.
|
| Sign In·View Thread·PermaLink | 5.00/5 (1 vote) |
|
|
|
 |
|
|
The GetFileNameStartString receive a parameter, but not use it:
private string GetFileNameStartString(string strFullName) { int posDot=_ImageFileName.LastIndexOf("."); int posSlash=_ImageFileName.LastIndexOf(@"\"); return _ImageFileName.Substring(posSlash+1,posDot-posSlash-1); } It should be change for private string GetFileNameStartString() { int posDot = _ImageFileName.LastIndexOf("."); int posSlash = _ImageFileName.LastIndexOf(@"\"); return _ImageFileName.Substring(posSlash + 1, posDot - posSlash -1 ); }
Or
private string GetFileNameStartString(string strFullName) { int posDot = strFullName.LastIndexOf("."); int posSlash = strFullName.LastIndexOf(@"\"); return strFullName.Substring(posSlash + 1, posDot - posSlash - 1); }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
|
The System.Drawing.Image class has a property called EncoderParameters. Try to iterate through them to find the one called Encoder.Compression and then try to get its value.
|
| Sign In·View Thread·PermaLink | 2.44/5 (5 votes) |
|
|
|
 |
|
|
In case someone needs this, I was unable to find a way to get the compression using GDI+ but you can do it by reading the TIFF file directly. Some resources:
TIFF Specification: http://partners.adobe.com/asn/developer/PDFS/TN/TIFF6.pdf
A nice summary of all the possible values of the compression tag: (note that not all are supported by the .net framework) http://www.awaresystems.be/imaging/tiff/tifftags/compression.html
It's a bit of work 
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Hi there,
No work at all.
Here is a sample:
Enum Compression None RLE PackBits CCITT3 CCITT4 LZW End Enum
Private Function GetTIFFCompression(ByVal bmp As Bitmap) As Compression Dim proplist As Array = bmp.PropertyIdList Dim ID As Integer = proplist.IndexOf(proplist, 259) Dim prop() As System.Drawing.Imaging.PropertyItem prop = bmp.PropertyItems Dim rCompression As Compression rCompression = prop(ID).Value(0) Return rCompression End Function
Regards
|
| Sign In·View Thread·PermaLink | 2.60/5 (2 votes) |
|
|
|
 |
|
|
Thanks for the tip - I had to write an IFD reader at work to get this info 
(I have to admit though, I enjoyed writing the reader!)
|
| Sign In·View Thread·PermaLink | 2.00/5 (1 vote) |
|
|
|
 |
|
|
Don't forget that TIFF acts container - so techically any frame (read as page) can contain any type of image - or even binary data that can not be understood by anyone else except your application. The most common compressions that TIFF files use are: Packbits (MAC RLE), JPEG (Progessive/sequential, WANG), ZIP, LZW for colors and JBIG (Enhanced JBIG), ITU G3/4 (CCIT3/CCIT4, Modified G3) for binary only (1bit). Binary files are usually used for faxed B/W documents (RFC2301 for more info); but color TIFF containters are more application definied and are not standardized to date.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
Thanks for the article and the Code. It helpt out a lot in the merger and splitting of Tiff files. There is however one little issue regarding the implemented Dispose() function.
Here is my implementation of the Dispose function:
public void Dispose() { if ( image != null ) // Checks whether the image object was assigned before calling the Dispose. image.Dispose(); System.GC.SuppressFinalize(this); }
Regards, Arjo.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
I receive a general GDI error when I try to split a multipage .tif:
private void Form1_Load(object sender, System.EventArgs e) { folderBrowserDialog1.SelectedPath = "c:";
}
private void button2_Click(object sender, System.EventArgs e) { folderBrowserDialog1.ShowDialog(); textBox1.Text = folderBrowserDialog1.SelectedPath; }
private void button1_Click(object sender, System.EventArgs e) { openFileDialog1.InitialDirectory = "c:\\" ; openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ; openFileDialog1.FilterIndex = 2 ; openFileDialog1.RestoreDirectory = true ;
if(openFileDialog1.ShowDialog() == DialogResult.OK) { TiffManager Splitter = new TiffManager(openFileDialog1.FileName); ArrayList splitedFileNames=new ArrayList(); splitedFileNames = Splitter.SplitTiffImage(textBox1.Text, System.Drawing.Imaging.EncoderValue.CompressionNone); }
}
|
| Sign In·View Thread·PermaLink | 1.67/5 (3 votes) |
|
|
|
 |
|
|
 |
|
|
I guess that you forgot to set the TempWorkingDir property, it will in good shape after setting that. Sorry for I do not monitor for my own post at the regular basis.
|
| Sign In·View Thread·PermaLink | 1.75/5 (3 votes) |
|
|
|
 |
|
|
Could use default system temp dir, if none has been set
public string TempWorkingDir { get { if (_TempWorkingDir == string.Empty) _TempWorkingDir = System.IO.Path.GetTempPath(); return _TempWorkingDir; } set{ _TempWorkingDir=value; } }
|
| Sign In·View Thread·PermaLink | 1.75/5 (4 votes) |
|
|
|
 |
|
|
thanks for the information! the docs on using FrameDimensions was a little scant, but seeing your code cleared that up a bit. keep up the good work.
|
| Sign In·View Thread·PermaLink | 2.00/5 (6 votes) |
|
|
|
 |