반응형

[java]zip파일로 묶어 저장하기

INTRO

 

 

여러 파일들을 zip파일로 묶어서 저장하는 방법입니다.

CONTENTS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public void zipFileDown(String zipFilePath, String zipFileName) {
 
        String[] files = {"    a.png ",
                          "    b.png ",
                          "    c.png ",
                          "    d.png "
                          };
        byte[] buf = new byte[1024];
        
        try {
            ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFilePath+zipFileName));
            System.out.println("zip파일 생성 성공, 경로+파일 = " +zipFilePath+zipFileName);
         
            for (int i=0; i<files.length; i++) {
                
                FileInputStream in = new FileInputStream(files[i]);
                Path p = Paths.get(files[i]);
                String fileName = p.getFileName().toString();
                
                ZipEntry ze = new ZipEntry(fileName);
                out.putNextEntry(ze);
                int len;
                while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                }
                out.closeEntry();
                in.close();
            }
                  
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
}
cs

 

 

 

 

 

 

 

 

 



OUTRO

이 소스를 응용한다면 zip파일로 묶어 다운로드 기능까지 구현한다면 훨씬 멋진 기능이 되겠죠??

반응형

'Programming > Java' 카테고리의 다른 글

[java]tif, tiff파일을 png파일로 변환하기  (0) 2022.09.05
[JAVA]문자열 치환,삭제 replace();  (0) 2022.09.05
반응형

[jquery]영역프린트하기, window.print();

INTRO

 

web image viewer의 세번 째 기능 : 이미지 프린트1

 

 

 

이미지 뷰어의 기능 중 웹에서 프린트하는 기능입니다. 이 기능은 javaScript의 기본 기능으로 아주 간단한 정도의 프린트 제어를 할 수있습니다.

 

장점 : ActiveX 가 필요 없음

단점 : ActiveX 를 사용하지 않으므로 각 개인PC의 설정을 가져와 사용 할수 없음

        -  예를 들어 머리말/꼬리말 등의 제어, 기본프린터로 설정된 프린터로 바로인쇄 등

 

 

 

CONTENTS

 

 

<스크립트 부분>

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<script language="JavaScript"> 
    function print() { 
      if (document.all && window.print) { 
        window.onbeforeprint = bef; 
        window.onafterprint = aft; 
        window.print(); 
      } 
    } 
    
    function bef() { 
      if (document.all) { 
        contents.style.display = 'none'
        printArea.innerHTML = document.all['printArea'].innerHTML;
      } 
    }
 
    function aft() { 
      if (document.all) { 
        contents.style.display = 'block'
        printArea.innerHTML = ""
      } 
    } 
</script>
cs
 
<화면 내용>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<DIV ID="contents"> 
    <input type="button" value="인쇄" onclick="print();">
    <DIV id="printArea" >
      <%--
       프린트할 내용을 코딩합니다.
       --%>
    </DIV>
</DIV>
 
<DIV ID="printArea">
       <%--
       실제 프린트가 되는 영역입니다. 
           contents는 display가 none이 되며 현재영역에 소스코드를 복사하여 인쇄합니다.
       --%> 
</DIV> 
cs

 

 

 

OUTRO

※ ActiveX를 이용한 프린트 기능은 다음 포스팅으로...

 

 

출처 : http://zekill.pe.kr/blog/83

반응형
반응형

[jquery]이미지 확대/축소

INTRO

 

web image viewer의 두번 째 기능 : 이미지의 확대 / 축소

 

 

 

이미지 뷰어의 기능 중 이미지 확대/축소기능을 웹으로 구현하는 방법입니다.

 

- 버튼 클릭 시 확대 / 축소 

 

 

 

 

- selectBox에 확대 / 축소 구간을 정하고(이 글에서는 50%~300%) 클릭 시 스케일 조정

 

 

 

CONTENTS

 

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<div>
 
<button id="scale_up" >이미지 확대</button>
 
<select id="selectBox">
 
<option value="50" onclick="scaleOpt('50');" >50%</option>
 
<option value="100" onclick="scaleOpt('50');" >100%</option>
 
<option value="150" onclick="scaleOpt('50');" >150%</option>
 
...
 
...
 
...
 
</select>
 
<button id="rotateR" >이미지 축소</button>
 
<img id="bigImg" src="" style="width: 644px; height: 912px;">
 
</div>
cs

 

Script.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<script type="text/javascript">
 
// selectBox로 스케일 조정
 
// 이미지의 크기가 너무 클 경우 팝업창에 한번에 보이지 않을 수 있으니 처음 가져온 이미지의 크기를 저장합니다.
 
var width = 644;                
 
var height = 912;
 
function scaleOpt(scale){
 
    $("#bigImg").css("width", width*scale);
 
    $("#bigImg").css("height", height*scale);
 
}
 
 
 
//이미지 확대
 
var selectBoxVal;
 
$('#scale_up').click(function() {
 
        selectBoxVal = parseInt($("#selectBox").val());
 
        if(selectBoxVal < 300){
 
            $("#selectBox").val(selectBoxVal+10).prop("selected"true);
 
            $("#bigImg").css("width", width*($("#selectBox").val()/100));
 
            $("#bigImg").css("height", height*($("#selectBox").val()/100));
 
        }
 
        else if(selectBoxVal == 300){
 
            alert("최대 확대 배율입니다.");
 
        }
 
});
 
// 이미지 축소
 
$('#scale_down').click(function() { 
 
        selectBoxVal = parseInt($("#selectBox").val());
 
        if(selectBoxVal > 50){
 
            $("#selectBox").val(selectBoxVal-10).prop("selected"true);
 
            $("#bigImg").css("width", width*($("#selectBox").val()/100));
 
            $("#bigImg").css("height", height*($("#selectBox").val()/100));
 
        }
 
        else if(selectBoxVal == 50){
 
            alert("최대 축소 배율입니다.");
 
        }
 
});
 
</script>
cs

 

 

 

OUTRO

더 쉬운 방법이 있으면 댓글달아주세요!!

 

반응형
반응형

[java]tif, tiff파일을 png파일로 변환하기

 

INTRO

 

tif파일 : 

TIFF (Tagged Image File Format)는 앨더스(Aldus)사와 마이크로소프트사가 공동 개발한 이미지 저장 포맷으로 

 

보통 팩스로 받은 파일이 tif형식으로 이루어진 경우가 많습니다. 여러장의 팩스를 받았을 경우 하나의 파일 안에 여러 이미지가 있습니다.(참고자료출처 :http://kr.aving.net/news/view.php?articleId=1940)

 

팩스문서, pdf파일과 같은 한개의 파일 안에 여러개의 이미지가 있는 경우 웹에서는 바로 로드하지 못합니다.

이럴 때 서버에서 tif파일을 읽어 png 파일로 분할하여 사용하기 편한 형식으로 바꿔 html에서 제어하면 됩니다.

 

 

 

 

CONTENTS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.io.File;
 
import java.io.FileNotFoundException;
 
 
 
import com.sun.media.jai.codec.FileSeekableStream;
 
import com.sun.media.jai.codec.ImageCodec;
 
import com.sun.media.jai.codec.ImageDecoder;
 
import com.sun.media.jai.codec.TIFFEncodeParam;
 
 
 
public static createPng(path, name){
 
        String rename = name.replace(".tif""");
 
        String pngFile = "";
 
        try {
 
            FileSeekableStream fss = new FileSeekableStream(path+name);
 
            ImageDecoder imgdec = ImageCodec.createImageDecoder("tiff", fss, null);
 
            int count = imgdec .getNumPages();
 
            int startPage = 0;
 
            String strCount = Integer.toString(count);
 
            TIFFEncodeParam param = new TIFFEncodeParam();
 
            param.setCompression(TIFFEncodeParam.COMPRESSION_GROUP4);
 
            param.setLittleEndian(false);
 
            
 
            String filePath = "D:/testFolder/"+rename+"_";        // 파일이 생성되는 경로, 파일을 읽어오는 경로
 
            
 
            for (int i = 0; i < count; i++) {
 
                RenderedImage page = dec.decodeAsRenderedImage(i);
 
                BufferedImage image = PlanarImage.wrapRenderedImage(page).getAsBufferedImage();
 
                File outputfile = new File(filePath+count +"_"+(i+1)+".png");
 
                pngFile += filePath+count +"_"+(i+1)+".png&";
 
                ImageIO.write(image, "png", outputfile);
 
            }
 
        } catch (FileNotFoundException e) {
 
            e.printStackTrace();
 
        } catch (IOException e) {
 
            e.printStackTrace();
 
        } catch (Exception e) {
 
            e.printStackTrace();
 
        }
 
    }
cs

 

 

OUTRO

참고자료 및 자료출처 : https://github.com/sjh010/tifViewer/blob/master/src/main/java/com/mobileleader/tifleader/util/ConvertUtil.java

반응형

'Programming > Java' 카테고리의 다른 글

[java]zip파일로 묶어 저장하기  (0) 2022.09.05
[JAVA]문자열 치환,삭제 replace();  (0) 2022.09.05

+ Recent posts