public static Bitmap[] gdcmBitmap2Bitmap(gdcm.Bitmap bmjpeg2000) { // przekonwertuj teraz na bitmapę C# uint cols = bmjpeg2000.GetDimension(0); uint rows = bmjpeg2000.GetDimension(1); uint layers = bmjpeg2000.GetDimension(2); // wartość zwracana - tyle obrazków, ile warstw Bitmap[] ret = new Bitmap[layers]; // bufor byte[] bufor = new byte[bmjpeg2000.GetBufferLength()]; if (!bmjpeg2000.GetBuffer(bufor)) { throw new Exception("błąd pobrania bufora"); } // w strumieniu na każdy piksel 2 bajty; tutaj LittleEndian (mnie znaczący bajt wcześniej) for (uint l = 0; l < layers; l++) { Bitmap X = new Bitmap((int)cols, (int)rows); double[,] Y = new double[cols, rows]; double m = 0; for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { // współrzędne w strumieniu int j = ((int)(l * rows * cols) + (int)(r * cols) + (int)c) * 2; Y[r, c] = (double)bufor[j + 1] * 256 + (double)bufor[j]; // przeskalujemy potem do wartości max. if (Y[r, c] > m) { m = Y[r, c]; } } } // wolniejsza metoda tworzenia bitmapy for (int r = 0; r < rows; r++) { for (int c = 0; c < cols; c++) { int f = (int)(255 * (Y[r, c] / m)); X.SetPixel(c, r, Color.FromArgb(f, f, f)); } } // kolejna bitmapa ret[l] = X; } return(ret); }
public static System.Drawing.Bitmap[] gdcmBitmap2Bitmap(gdcm.Bitmap bmjpeg2000) { uint columns = bmjpeg2000.GetDimension(0); uint rows = bmjpeg2000.GetDimension(1); uint layers = bmjpeg2000.GetDimension(2); System.Drawing.Bitmap[] ret = new System.Drawing.Bitmap[layers]; byte[] bufor = new byte[bmjpeg2000.GetBufferLength()]; if (!bmjpeg2000.GetBuffer(bufor)) { throw new Exception("Błąd pobrania bufora"); } for (uint l = 0; l < layers; l++) { System.Drawing.Bitmap X = new System.Drawing.Bitmap((int)columns, (int)rows); double[,] Y = new double[columns, rows]; double m = 0; for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { int j = ((int)(l * rows * columns) + (int)(r * columns) + (int)c) * 2; Y[r, c] = (double)bufor[j + 1] * 256 + (double)bufor[j]; if (Y[r, c] > m) { m = Y[r, c]; } } } for (int r = 0; r < rows; r++) { for (int c = 0; c < columns; c++) { int f = (int)(255 * (Y[r, c] / m)); X.SetPixel(c, r, System.Drawing.Color.FromArgb(f, f, f)); } } ret[l] = X; } return(ret); }