I need to extract tiles from a tif image and write them in jpg format.
Based on a previous search, I wrote some C# code that works in a C# WinForm project on my desktop. Then I had the idea to put it as a WebService but i cannot do it, because this code is using Marshal.Copy
that doesn't work on the remote server (despite I have there the full trust
mode. I have read some comment saying that this could be the problem, but it isn't, in my case).
The source image is Tif
, therefore I have read the part of the image corresponding to the tile, in a buffer named output
. If nothing better is possible, I could accept to set the resulting image Pixel by Pixel, but I don't see how to do it in C#. In other words I am not able to set the pixels in the resulting image, using the bytes[] that I extracted from the Tif
.
The code which works on the desktop is:
using (var image = new Bitmap(W, H, System.Drawing.Imaging.PixelFormat.Format24bppRgb))
{
var bmpData = image.LockBits(new Rectangle(0, 0, W, H),ImageLockMode.WriteOnly,
Image.PixelFormat);
var ptr = bmpData.Scan0;
Marshal.Copy(output, 0, ptr, output.Length);
image.UnlockBits(bmpData);
image.Save(origin + "\\" + TileName, ImageFormat.Png)
}