게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
[ASP.NET][자답] 모바일로 촬영한 세로사진 회전하는 방법
게시물ID : programmer_14011짧은주소 복사하기
작성자 : 릴라강
추천 : 0
조회수 : 2573회
댓글수 : 4개
등록시간 : 2015/10/21 16:36:57
아래 내용에 본삭금 뒤늦게 걸고 자답으로 수정했더니
태그 안닫힌게 하나 있는지 에러가 나네요. ㄷㄷㄷ
해서 혹시나 필요하신분 참고하시라고 새 글로 올립니다.


<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" Debug="true" %>
<%@ Import Namespace = "System.IO" %>
<%@ Import Namespace = "System.Drawing" %>
<%@ Import Namespace = "System.Drawing.Imaging" %>
<%@ Import Namespace = "System.Text" %>
<script runat="server">

//전역변수 선언
string srvRoot, srvPath, srcPath;

protected void Page_Load(object sender, EventArgs e){
//전역변수 초기화
srvRoot = Request["srvRoot"];
srvPath = Request["srvPath"];
srcPath = Request["srcPath"];
if( srvRoot == "" ){ srvRoot = Server.MapPath("\\"); }
// 파일컨트롤 선언 및 초기화
HttpPostedFile requestFile = Request.Files[0];
// 파일명, 전체경로 설정
string fileName = requestFile.FileName;
string fullPath = srvRoot + srvPath + fileName;
// 서버에 파일폴더가 존재하지 않을시 생성
DirectoryInfo di = new DirectoryInfo(srvRoot + srvPath);
if( !di.Exists ){ di.Create(); }
// 파일 중복체크
string fnm, ext = fileName.Substring(fileName.LastIndexOf(".") + 1);
FileInfo fi = new FileInfo(fullPath);
if( fi.Exists ){
int fidx = 0;
fnm = fileName.Substring(0, fileName.LastIndexOf("."));
do{
fidx++;
fileName = fnm + "[" + fidx.ToString() + "]." + ext;
fullPath = srvRoot + srvPath + fileName;
fi = new FileInfo(fullPath);
}while( fi.Exists );
}
try{
requestFile.SaveAs(fullPath);
// 파일 이미지의 확장자가 JPG 또는 JPEG 일 경우 EXIF 데이터 추출하여 이미지 270도 회전
string fileext = fullPath.Substring(fullPath.LastIndexOf(".") + 1, 3);
fileext = fileext.ToUpper();
if( fileext == "JPG" ){
string file = fullPath;
FileInfo info = new FileInfo(file);
long filesize = info.Length;
FileStream stream = new FileStream(file,FileMode.Open,FileAccess.Read);
System.Drawing.Image img = System.Drawing.Image.FromStream(stream,false,false);
PropertyItem item = img.GetPropertyItem(0x0112);
int orientation = item.Value[0];
stream.Dispose();
if( orientation == 6 ){
System.Drawing.Image rotateimg = System.Drawing.Image.FromFile(fullPath);
rotateimg.RotateFlip(RotateFlipType.Rotate270FlipXY);
rotateimg.Save(fullPath);
rotateimg.Dispose();
}
}
Response.Write("{\"result\":\"" + fileName + "\"}");
}catch{
Response.Write("{\"result\":false, \"error\":\"\"}");
}
}
</script>




파란색 부분이 새롭게 추가된 부분입니다.
정답 찾는데 도움을 주신 구글신님과 스택오버플로의
이름모를 해외 개발자님들(?)께 감사드립니다. ㅋㅋ
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호