Example usage for javax.imageio.stream FileImageInputStream length

List of usage examples for javax.imageio.stream FileImageInputStream length

Introduction

In this page you can find the example usage for javax.imageio.stream FileImageInputStream length.

Prototype

public long length() 

Source Link

Document

Returns the length of the underlying file, or -1 if it is unknown.

Usage

From source file:com.lynk.hrm.ui.dialog.InfoEmployee.java

private void startRead() {
    new SwingWorker<String, Void>() {
        @Override/*  w  w w.j  a  v a2 s .co m*/
        protected String doInBackground() throws Exception {
            int result;
            IdCard idCard = new IdCard();
            String photoPath = System.getProperty("user.dir") + "/temp/" + "idCard.bmp";
            WString imageFile = new WString(photoPath);
            result = IdCardLibrary.INSTANCE.OpenCardReader(0, 4, 115200);
            if (result != 0) {
                showErrorMsg(IdCard.getErrorMsg(result));
                return null;
            }
            try {
                result = IdCardLibrary.INSTANCE.GetPersonMsgW(idCard, imageFile);
                if (result == 0) {
                    uiName.setText(idCard.getName());
                    uiNamePy.setText(PinyinUtil.getPinpin(idCard.getName()));
                    uiIdCard.setText(idCard.getCardId());
                    uiGender.setText(idCard.getSex());
                    uiBirthday.setText(idCard.getBirthday());
                    uiAge.setText(Integer.toString(Utils.getAge(idCard.getBirthday())));
                    uiCensusAddress.setText(idCard.getAddress());

                    RenderedImage imgOri = ImageIO.read(new File(photoPath));
                    File imgFile = File.createTempFile("photo_", ".png",
                            new File(System.getProperty("user.dir") + "/temp"));
                    ImageIO.write(imgOri, "png", imgFile);

                    uiPhoto.setImage(imgFile.getPath());
                    uiPhoto.putClientProperty("path", imgFile.getPath());
                    FileImageInputStream fiis = new FileImageInputStream(new File(imgFile.getPath()));
                    byte[] photoByte = new byte[(int) fiis.length()];
                    fiis.read(photoByte);
                    fiis.flush();
                    fiis.close();
                    uiPhoto.putClientProperty("photo", photoByte);

                    IdCardLibrary.INSTANCE.CloseCardReader();
                }
                Thread.sleep(1000);
            } catch (Exception e) {
                showErrorMsg(e);
            }
            return null;
        }
    }.execute();
}