示例#1
0
        /*Converte l'array di byte codificato in jpeg2000 in una bitmap*/
        public Bitmap ret_cie_bitmap()
        {
            BitmapImageCreator.Register();
            var por = J2kImage.FromBytes(cie_jpg2k_image);

            return(por.As <Bitmap>());
        }
示例#2
0
        public static string decodeJp2(String filepath, String filename, String base64)
        {
            BitmapImageCreator.Register();
            filepath = filepath + "\\" + filename;
            var enc = Convert.FromBase64String(base64);

            File.WriteAllBytes(filepath, enc);
            return(filepath);
        }
示例#3
0
 //https://www.nuget.org/packages/CSJ2K/
 public static string encodeJp2(String path)
 {
     try
     {
         BitmapImageCreator.Register();
         Bitmap image = J2kImage.FromFile(path).As <Bitmap>();
         return(ImageToBase64(image, System.Drawing.Imaging.ImageFormat.Jpeg));
     }
     catch (Exception ex)
     {
         Console.WriteLine("encodeJp2 '" + path + "' error: " + ex.Message);
         return("");
     }
 }
示例#4
0
        /// <summary>
        ///     <para>
        ///         Converts single page jpeg2000 Scans found within the package into (multi-paged) pdf document.
        ///         Per document or dossier (with direct dateiRef's) one pdf is created. The metadata information in the package is
        ///         updated to reflect the changes made.
        ///     </para>
        ///     <para>The following assumptions are made:</para>
        ///     <list type="bullet">
        ///         <item>JPEG 2000 Files have the extension .jp2</item>
        ///         <item>The .jp2 may be accompanied by a premis xml file. The premis filename is "[jpeg200Filename]_premis.xml</item>
        ///         <item>
        ///             Within one document or (dossier with dateiRef) only .jp2 files are allowed.
        ///             If other file types are mixed in, (except for the premis files) the conversion silently fails for that
        ///             document.
        ///         </item>
        ///         <item>The premis files are removed after the pdf creation took place.</item>
        ///     </list>
        /// </summary>
        /// <param name="paket">The package to be converted</param>
        /// <param name="folder">The root folder where the files can be found.</param>
        /// <param name="settings">The conversion settings</param>
        public void ConvertSingleJpeg2000ScansToPdfDocuments(PaketDIP paket, string folder)
        {
            rootFolder     = folder;
            paketToConvert = paket;

            // Default settings for Image conversion
            encoderParameters = new EncoderParameters(1);
            var encoderParameter = new EncoderParameter(Encoder.Quality, settings.JpegQualitaetInProzent);

            encoderParameters.Param[0] = encoderParameter;
            BitmapImageCreator.Register();

            foreach (var ordnungssystemposition in paket.Ablieferung.Ordnungssystem.Ordnungssystemposition)
            {
                ProcessOrdnungssystemPosition(ordnungssystemposition);
            }
        }
        static void Main(string[] args)
        {
            // from byte array
            byte[]       imageDataInBinary  = File.ReadAllBytes(@"C:\Users\aniketchadha\Pictures\v.jp2");
            MemoryStream memoryStreamObject = new MemoryStream();

            memoryStreamObject.Write(imageDataInBinary, 0, imageDataInBinary.Length);
            BitmapImageCreator.Register();

            // from file
            CSJ2K.Util.PortableImage portableImageObject = CSJ2K.J2kImage.FromFile(@"D:\Jpeg2k.Samples-master\Jpeg2k.Samples-master\Samples\Sample Data\balloon.j2c");
            try
            {
                var img = portableImageObject.As <System.Drawing.Image>();
                img.Save(@"C:\Users\aniketchadha\Pictures\balloon2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.ToString());
            }
        }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="readAddress">Reading address will promp for password, to avoid it don't read the address.</param>
        /// <returns></returns>
        public Citizen Read(bool readAddress = true)
        {
            // enable bitmap convertion for CSJ2K
            BitmapImageCreator.Register();

            // connect to card
            Pteid.Init(null);
            Pteid.SetSODChecking(0);

            // read data
            var citizen = new Citizen();

            ReadIDField(citizen);
            ReadCertificates(citizen);
            ReadPicture(citizen);

            if (readAddress)
            {
                ReadAddress(citizen);                 // will request address password
            }

            return(citizen);
        }
示例#7
0
        /// <summary>
        /// Obters the dados cartao cidadao.
        /// </summary>
        /// <param name="leitor">The leitor.</param>
        /// <returns></returns>
        private Cidadao ObterDadosCartaoCidadao(string leitor)
        {
            Cidadao cidadao = null;

            try
            {
                Pteid.Init(leitor);
                Pteid.SetSODChecking(0);

                var x =
                    Pteid.GetID();

                var pins =
                    Pteid.GetPINs();

                var pinMorada =
                    pins.Where(fi => fi.id == 131).FirstOrDefault();

                PteidAddr address = null;

                // Descomentar linhas abaixo para ler a morada.
                // Nota: Vai pedir o PIN de morada, geralmente é: 0000

                //if (pinMorada.triesLeft > 0)
                //{
                //    address =
                //        Pteid.GetAddr();
                //}

                // Obter a fotografia e converter para byte[].

                var y = Pteid.GetPic();

                byte[] photo = null;

                using (MemoryStream ms = new MemoryStream(y.picture, 0, y.piclength, false))
                {
                    BitmapImageCreator.Register();

                    var tempImage = CSJ2K.J2kImage.FromStream(ms);
                    ms.Close();

                    var img = tempImage.As <Bitmap>();
                    using (MemoryStream ms2 = new MemoryStream())
                    {
                        img.Save(ms2, ImageFormat.Jpeg);

                        photo = ms2.ToArray();
                    }
                }

                cidadao = new Cidadao()
                {
                    NomeCompleto     = ConverterString(x.firstname + " " + x.name),
                    NumBI            = x.numBI,
                    NIF              = x.numNIF,
                    SNS              = x.numSNS,
                    SS               = x.numSS,
                    Sexo             = x.sex,
                    DataValidade     = DateTime.Parse(x.validityDate),
                    DataNascimento   = DateTime.Parse(x.birthDate),
                    Nacionalidade    = ConverterString(x.nationality),
                    Fotografia       = Convert.ToBase64String(photo),
                    EntidadeEmissora = ConverterString(x.deliveryEntity),

                    //TODO: Adicionar outros campo
                };

                if (address != null)
                {
                    // TODO: Caso a prorpiedade "streettype" venha a vazio ler a rua no campo "place".

                    cidadao.Rua          = ConverterString(address.streettype) + " " + ConverterString(address.street) + ", " + ConverterString(address.door);
                    cidadao.CodigoPostal = address.cp4 + "-" + address.cp3;
                    cidadao.Localidade   = ConverterString(address.locality);
                    cidadao.Municipio    = ConverterString(address.municipalityDesc);
                    cidadao.Distrito     = ConverterString(address.districtDesc);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                Pteid.Exit(0);
            }

            return(cidadao);
        }
示例#8
0
文件: Program.cs 项目: radtek/csj2k
        private static void Main(string[] args)
        {
            BitmapImageCreator.Register();

            File.Delete("file11.jp2");
            File.Delete("file12.jp2");
            File.Delete("file13.jp2");
            File.Delete("file14.jp2");

            using (var ppm = File.OpenRead("a1_mono.ppm"))
            {
                var enc = J2kImage.ToBytes(J2kImage.CreateEncodableSource(ppm));
                File.WriteAllBytes("file11.jp2", enc);
            }

            using (var ppm = File.OpenRead("a2_colr.ppm"))
            {
                var enc = J2kImage.ToBytes(J2kImage.CreateEncodableSource(ppm));
                File.WriteAllBytes("file12.jp2", enc);
            }

            using (var ppm = File.OpenRead("c1p0_05_0.pgx"))
            {
                var enc = J2kImage.ToBytes(J2kImage.CreateEncodableSource(ppm));
                File.WriteAllBytes("file13.jp2", enc);
            }

            using (var bitmap = (Bitmap)Image.FromFile("logo.png"))
            {
                var enc = J2kImage.ToBytes(bitmap);
                File.WriteAllBytes("file14.jp2", enc);
            }


            for (int i = 1; i <= 14; i++)
            {
                try
                {
                    HiPerfTimer timer = new HiPerfTimer();
                    timer.Start();
                    Bitmap image = J2kImage.FromFile("file" + i + ".jp2").As <Bitmap>();
                    timer.Stop();
                    Console.WriteLine("file" + i + ": " + timer.Duration + " seconds");

                    Bitmap histogram = GenerateHistogram(image);

                    if (image.Height > 2 * histogram.Height)
                    {
                        Graphics g = Graphics.FromImage(image);
                        g.DrawImage(histogram, 0, 0);
                    }

                    ImageDialog dlg = new ImageDialog();
                    dlg.Text              = "file" + i + ".jp2";
                    dlg.ClientSize        = new Size(image.Width, image.Height);
                    dlg.pictureBox1.Image = image;
                    dlg.ShowDialog();
                }
                catch (Exception e)
                {
                    Console.WriteLine("file" + i + ":\r\n" + e.Message);
                    if (e.InnerException != null)
                    {
                        Console.WriteLine(e.InnerException.Message);
                        Console.WriteLine(e.InnerException.StackTrace);
                    }
                    else
                    {
                        Console.WriteLine(e.StackTrace);
                    }
                }
            }
        }