Пример #1
0
 public static extern J2K_Error Close(ref J2K_Image image);
Пример #2
0
 public static extern J2K_Error SelectTiles(ref J2K_Image image, int startTile, int endTile, bool select);
Пример #3
0
 public static extern J2K_Error Decode(ref J2K_Image image, string options);
Пример #4
0
 public static extern J2K_Error GetMetadata(ref J2K_Image image, int no, ref J2K_Metadata type, ref IntPtr data, ref int size);
Пример #5
0
 public static extern J2K_Error GetInfo(ref J2K_Image image);
Пример #6
0
 public static extern J2K_Error OpenMemory(byte[] buffer, uint size, ref J2K_Image image);
Пример #7
0
 public static extern J2K_Error OpenFile(string fileName, ref J2K_Image image);
Пример #8
0
        private void ShowImage(string fileName, int resolution)
        {
            // Open picture file and obtain an image handle
            J2K_Image img = new J2K_Image(); img.version = J2K_Codec.Version;


            J2K_Error err = J2K_Codec.OpenFile(fileName, ref img);

            if (err != J2K_Error.Success)
            {
                // If error then show the error message and exit function
                MessageBox.Show(J2K_Codec.GetErrStr(err), "Error");
                J2K_Codec.Close(ref img);
                return;
            }

            // Set resolution level and update Width and Height
            img.resolution = resolution;
            J2K_Codec.GetInfo(ref img);

            // Show to the user the file name and size
            InfoLabel.Text = string.Format("{0}  |  {1} x {2} x {3}",
                                           new FileInfo(fileName).Name, img.Width, img.Height, img.Components);

            // Create a bitmap info structure
            BITMAPINFO bmp = new BITMAPINFO();

            bmp.Size          = Marshal.SizeOf(bmp);
            bmp.Width         = img.Width;              // Image width
            bmp.Height        = img.Height;             // Image height
            bmp.Planes        = 1;
            bmp.BitCount      = 32;                     // Always 4 bytes per pixel
            bmp.Compression   = 0;                      // No compression (RGB format)
            bmp.SizeImage     = 0;
            bmp.XPelsPerMeter = 0;
            bmp.YPelsPerMeter = 0;
            bmp.ClrUsed       = 0;
            bmp.ClrImportant  = 0;

            // Create the bitmap in memory. The "bits" variable will receive a pointer
            // to the memory allocated for the bitmap.
            IntPtr bits    = IntPtr.Zero;
            IntPtr hBitmap = CreateDIBSection(IntPtr.Zero, ref bmp, 0, ref bits, IntPtr.Zero, 0);

            if (hBitmap == IntPtr.Zero)
            {
                // There was an error creating the bitmap
                J2K_Codec.Close(ref img);
                MessageBox.Show("Can't create bitmap - not enough memory?");
            }

            // Decode the image into the newly created bitmap memory (pointed to by the
            // "bits" variable).
            this.Cursor = Cursors.WaitCursor;

            img.buffer       = bits;
            img.buffer_bpp   = 4;
            img.buffer_pitch = img.Width * img.buffer_bpp;

            err = J2K_Codec.Decode(ref img, "bmp=1");
            if (err == J2K_Error.Success)
            {
                // Obtain a managed bitmap
                Bitmap result = Bitmap.FromHbitmap(hBitmap);

                // Show it in the image box
                pictureBox.Image = result;

                // Resize the window to embrace the image
                ResizeWindow(img.Width, img.Height);
            }
            else
            {
                // If error then show the error message
                MessageBox.Show(J2K_Codec.GetErrStr(err), "Error");
            }

            // Delete the DIB to release memory
            DeleteObject(hBitmap);

            // Close the image
            J2K_Codec.Close(ref img);

            // Restore cursor
            this.Cursor = Cursors.Default;
        }