수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

JMF를 이용한 웹캠 사진촬영 후 JPEG 파일로 저장하는 소스

에드가

2023.04.01

노트북에서 run.java를 실행시켰을때 노트북 웸켐의 드라이버를 잡아서 화면을 캡쳐해 jpeg로 저장하는 프로그램을 만들려합니다.

jpegcapture.java 소스입니다.

import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import javax.media.*;
import javax.media.format.*;
import javax.media.util.*;
import javax.media.control.*;
import javax.media.protocol.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import com.sun.image.codec.jpeg.*;
public class jpegcapture {

public static player player = null;
public capturedeviceinfo di = null;
public medialocator ml = null;
public buffer buf = null;
public image img = null;
public videoformat vf = null;
public buffertoimage btoi = null;
protected format[] videoformats = null;
public formatcontrol formatcontrol = null;
public jpegcapture() {
this.initdevice();
}
public void initdevice() {
//string str1 = vfw:logitech usb video camera:0;
string str = vfw:microsoft wdm image capture (win32):0;

di = capturedevicemanager.getdevice(str);
ml = di.getlocator();
try{
player = manager.createrealizedplayer(ml);
player.start();

formatcontrol = (formatcontrol)player.getcontrol ( javax.media.control.formatcontrol );
videoformats = di.getformats();
}catch(exception e){
e.printstacktrace();
}
}

public static void playerclose() {
player.stop();
player.close();
player.deallocate();
}
public void capture(string abspath){
framegrabbingcontrol fgc = (framegrabbingcontrol)player.getcontrol(javax.media.control.framegrabbingcontrol);
buf = fgc.grabframe();
// convert it to an image
btoi = new buffertoimage((videoformat)buf.getformat());
img = btoi.createimage(buf);
// save image
savejpg(img, abspath);
// 제가 볼때 이 부분에서 img 변수에 화상정보를 못 담는것 같은데... 그래서 저 밑에 버퍼이미지를 생성할때 제대로 담지 못하는 것 같습니다.
제 추측이 맞는지요..
}
public static void savejpg(image img, string s) {
bufferedimage bi = new bufferedimage(img.getwidth(null), img.getheight(null), bufferedimage.type_int_rgb);
graphics2d g2 = bi.creategraphics();
g2.drawimage(img, null, null);
fileoutputstream out = null;
try {
out = new fileoutputstream(s);
}catch (java.io.filenotfoundexception io){
system.out.println(file not found);
}
jpegimageencoder encoder = jpegcodec.createjpegencoder(out);
jpegencodeparam param = encoder.getdefaultjpegencodeparam(bi);
param.setquality(0.1f, false);
encoder.setjpegencodeparam(param);
try {
encoder.encode(bi);
out.close();
//}catch(java.io.ioexception io){
//system.out.println(ioexception);
//}
}catch(exception e){
e.printstacktrace();
}
}
}play.java 소스입니다.
public class play extends jpegcapture {
public static void main(string[] args){
jpegcapture cap = new jpegcapture();
cap.capture(c:\\test.jpg);
cap.playerclose();
}
}
이클립스에서 run.java를 실행시켰을때 나오는 오류메시지 입니다.

exception in thread main java.lang.nullpointerexception
at joocam.jpegcapture.savejpg(jpegcapture.java:69)
at joocam.jpegcapture.capture(jpegcapture.java:66)
at joocam.play.main(play.java:6)
다음은 jpegcapture.java 만 돌려 보았을때 나오는 오류메시지 입니다.

jpegcapture.java:65: warning: com.sun.image.codec.jpeg.jpegimageencoder is sun proprietary api and may be removed in a future release
jpegimageencoder encoder = jpegcodec.createjpegencoder(out);
^
jpegcapture.java:65: warning: com.sun.image.codec.jpeg.jpegcodec is sun proprietary api and may be removed in a future release
jpnbsp; jpegimageencoder encoder = jpegcodec.createjpegencoder(out);
^
jpegcapture.java:66: warning: com.sun.image.codec.jpeg.jpegencodeparam is sun proprietary api and may be removed in a future release
jpegencodeparam param = encoder.getdefaultjpegencodeparam(bi);
^
3 warnings

제가 볼때 savejpeg 함수에서 img 변수에 화상정보를 못 담는것 같은데... 그래서 저 밑에 버퍼이미지를 생성할때 제대로 담지 못하는 것 같습니다.
제 추측이 맞는지요..
맞다면.. 제대로 구동할수 있게 소스 수정 도와주시면 감사하겠습니다... ㅠ ㅠ

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

번호 제 목 글쓴이 날짜
2694696 텍스트박스 입력에 관한 문제입니다. 딥공감 2025-05-13
2694668 [질문] 페이퍼비전 PointLight 관련 질문 드려요.. 두바다찬솔 2025-05-13
2694611 Flash Lite 2.1에서 BitmapData와 Matrix 지원안하나요? (3) 이플 2025-05-12
2694582 IE & 파이어폭스 (2) 흙이랑 2025-05-12
2694553 무비클립안의 duplicate 발동이 안돼네요; 딥보라 2025-05-12
2694523 자바 애플릿 질문좀 ^^ (6) 동이 2025-05-12
2694494 [질문] JAVA 또는 C++ 로 프로그램 개발시.. 레지스터리 등록 관련 의문점? (3) 우람늘 2025-05-11
2694469 익스6에서 css버그 나오는것 해결방법좀요 !!!! (6) 원술 2025-05-11
2694442 로컬에선 잘 나오는데 운영에 반영하면 이상하게 나와요. (8) 목화 2025-05-11
2694412 [질문] 이미지 로딩후 사이즈 조절할때 (1) 아담 2025-05-11
2694391 설치형 블로그 쓰시는 분들 어떤거 쓰세요?? (7) AngelsTears 2025-05-10
2694362 Microsoft SQL Server에서 서버만드는법 어둠 2025-05-10
2694333 for문으로 돌린 이름의 제어 (4) 레이 2025-05-10
2694308 이미지 css 도와주세요 ㅠㅠ (2) 애기 2025-05-10
2694223 [급질문]스크롤스파이의 offset값 진나 2025-05-09
2694195 li에 이미지 넣고 세로로 메뉴 구성하는 경우 (1) 예님 2025-05-09
2694167 canvas 질문요. (4) 찬늘봄 2025-05-08
2694136 왜 이렇게 나오는지 이해가 잘 가지 않네요. 부탁드리겠습니다... (2) 세련 2025-05-08
2694111 div , css 공부하고있는데요 잘모르겠어요.. 도와주세요 ㅠ_ㅠ (10) 모람 2025-05-08
2694035 작업관리자 창에.. CPU사용 현황처럼 만들고 싶습니다. (1) 다올 2025-05-07
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com