public static void SaveImageRaster3DAsTIFF3D2(string save_path, IImageRaster <IRaster3DInteger, uint> image) { Stream destination_stream = new FileStream(save_path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None); TiffBitmapEncoder encoder = new TiffBitmapEncoder(); encoder.Compression = TiffCompressOption.None; for (int index_z = 0; index_z < image.Raster.Size2; index_z++) { Bitmap bitmap = ConvertToBitmapUInt16(image, index_z); BitmapSource bitmap_source = ToolsRendering.CreateBitmapSourceFromBitmap16Bit(bitmap); encoder.Frames.Add(BitmapFrame.Create(bitmap_source)); } encoder.Save(destination_stream); //TiffBitmapEncoder encoder = new TiffBitmapEncoder(destination_stream_, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); //Stream imageStreamSource = new FileStream(load_path, FileMode.Open, FileAccess.Read, FileShare.Read); //TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); //BitmapSource test_frame = decoder.Frames[0]; //int size_x = test_frame.PixelWidth; //int size_y = test_frame.PixelHeight; //int size_z = decoder.Frames.Count; //int bits_per_pixel = test_frame.Format.BitsPerPixel; //for (int index_z = 0; index_z < size_z; index_z++) //{ // // save each frame to a bytestream // BitmapSource frame = decoder.Frames[index_z]; // // img.CopyPixels(pixels, stride, 0) // MemoryStream byte_stream = new MemoryStream(); // // bitmap.Save(byte_stream, ImageFormat.Tiff); // // and then create a new Image from it // System.Drawing.Image image = System.Drawing.Image.FromStream(byte_stream); // // d //} }
public BitmapSource Render(RenderSourceType render_source) { IImageRaster <IRaster2DInteger, ElementValueType> rendered_image = inner_renderer.Render(render_source); BitmapFast bitmap_fast = new BitmapFast(rendered_image.Raster.Size0, rendered_image.Raster.Size1); bitmap_fast.Lock(); for (int y_index = 0; y_index < rendered_image.Raster.Size1; y_index++) { for (int x_index = 0; x_index < rendered_image.Raster.Size0; x_index++) { bitmap_fast.SetPixel(x_index, y_index, converter.Compute(rendered_image.GetElementValue(rendered_image.Raster.GetElementIndex(x_index, y_index)))); } } bitmap_fast.Unlock(); return(ToolsRendering.CreateBitmapSourceFromBitmap(bitmap_fast.Bitmap)); }