For a geoTransform .NET project i want to generate an output stream in jp1 format from a geoTiff file.
I use ImageMagik to manage jp2.
My problem occurs in the final part of the process.
I load my geoTiff file in an instance of ImageMagick
Code: Select all
imgResult = new MagickImage(imageIdentifier + "_crop.tiff");
Code: Select all
// Context for response
WebOperationContext context = WebOperationContext.Current;
context.OutgoingResponse.ContentType = streamFormat;
context.OutgoingResponse.Headers.Add("Content-Disposition", string.Format("inline;filename={0}.{1}", featureid, context.OutgoingResponse.ContentType.Substring(context.OutgoingResponse.ContentType.LastIndexOf('/') + 1)));
// Create outPut stream with jpeg or jp2 format based on initial request
if (streamFormat == "image/jp2")
{
magick.Write(responseStream, MagickFormat.Jp2);
}
else
{
magick.Write(responseStream, MagickFormat.Jpeg);
}
All is jpg2 format if it has not been processed with GDAL utility
The problem occurs with jp2 format when my geoTiff file has been cropped by GDAL utility "gdal_translate" or "gdalwarp".
I can display the geoTiff with a viewer such as IrfanViewer or Windows Viewer. But when it's loaded on the browser the image i get is white.
Please find result from command line tiffInfo:
for ImageBase (ok):
Code: Select all
TIFFReadDirectory: Warning, Unknown field with tag 34264 (0x85d8) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 34735 (0x87af) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 34736 (0x87b0) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 34737 (0x87b1) encountered.
TIFF Directory at offset 0x1ca09a (1876122)
Image Width: 900 Image Length: 811
Resolution: 96, 96
Bits/Sample: 8
Sample Format: unsigned integer
Compression Scheme: JPEG
Photometric Interpretation: RGB color
YCbCr Subsampling: 2, 2
Samples/Pixel: 4
Rows/Strip: 811
Planar Configuration: single image plane
Tag 34264: 0.000970,-0.000006,0.000000,-73.722622,0.000005,-0.000666,0.000000,
-50.173928,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,1.0000
00
Tag 34735: 1,1,0,7,1024,0,1,2,1025,0,1,1,2048,0,1,4326,2049,34737,7,0,2054,0,1
,9102,2057,34736,1,1,2059,34736,1,0
Tag 34736: 298.257224,6378137.000000
Tag 34737: WGS 84|
JPEG Tables: (289 bytes)
Code: Select all
TIFFReadDirectory: Warning, Unknown field with tag 34264 (0x85d8) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 34735 (0x87af) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 34736 (0x87b0) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 34737 (0x87b1) encountered.
TIFF Directory at offset 0x8 (8)
Image Width: 200 Image Length: 200
Resolution: 96, 96
Bits/Sample: 8
Sample Format: unsigned integer
Compression Scheme: None
Photometric Interpretation: RGB color
Extra Samples: 1<assoc-alpha>
Samples/Pixel: 4
Rows/Strip: 10
Planar Configuration: single image plane
Tag 34264: 0.000970,-0.000006,0.000000,-73.722622,0.000005,-0.000666,0.000000,
-50.173928,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,1.0000
00
Tag 34735: 1,1,0,7,1024,0,1,2,1025,0,1,1,2048,0,1,4326,2049,34737,7,0,2054,0,1
,9102,2057,34736,1,1,2059,34736,1,0
Tag 34736: 298.257224,6378137.000000
Tag 34737: WGS 84|
the original geoTiff is created programatically from a stream and geotransform information calculate with metadata:
This is how i set basic tifftag (i could give more details about this process)
Code: Select all
// Use ImageMagick to load stream and save as temp bmp file.
// This API enable to manage jp2 formatted stream
MagickImage img = new MagickImage(sourceStream);
string tempFile = Path.GetDirectoryName(destinationPath) + "\\" + Path.GetFileNameWithoutExtension(destinationPath) + ".bmp";
img.Write(tempFile);
using (Bitmap bmp = new Bitmap(tempFile))
{
...
...
else if (pixFormat == PixelFormat.Format32bppArgb)
{
tif.SetField(TiffTag.IMAGEWIDTH, bmp.Width);
tif.SetField(TiffTag.IMAGELENGTH, bmp.Height);
tif.SetField(TiffTag.BITSPERSAMPLE, 8);
tif.SetField(TiffTag.COMPRESSION, Compression.JPEG);
tif.SetField(TiffTag.JPEGQUALITY, 100);
tif.SetField(TiffTag.PHOTOMETRIC, Photometric.RGB);
tif.SetField(TiffTag.ROWSPERSTRIP, bmp.Height);
tif.SetField(TiffTag.XRESOLUTION, bmp.HorizontalResolution);
tif.SetField(TiffTag.YRESOLUTION, bmp.VerticalResolution);
tif.SetField(TiffTag.SAMPLESPERPIXEL, 4);
tif.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
tif.SetField(TiffTag.SAMPLEFORMAT, 1);
tif.SetField(TiffTag.DATATYPE, 2);
}
...
...
Best regards,
Christophe.