파이썬 & 오픈소스 개발 질문과 답변 게시판
사진 이미지를 binary 16진수 string 으로 변환하여 외부 웹서비스를 호출하고, 변환된 값을 전달하려 합니다.
visual studio 에서 디버깅 뜨면서 값을 체크하면 데이터는 나오는데........
웹서비스 호출하면 성공 리턴 값이 오는 것이 아니라
The process cannot access the file '파일경로\파일명.jpg' because it is being used by another process.
라는 메세지가 조회됩니다.
혹시 FileStream 사용을 잘 못해서 오류가 표시되는 걸까요 ? ㅠㅠ
왜 그런지 아시는 분은 알려주세요
소스는 아래와 같습니다.
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string empnum;
string name;
private string imageToHex(Image img)
{
byte[] byteArray = null;
using (MemoryStream ms = new MemoryStream())
{
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
ms.Seek(0, 0);
byteArray = ms.ToArray();
}
string hexString = "";
foreach (byte b in byteArray)
{
hexString += b.ToString("x2");
}
return hexString;
}
public Form1()
{
InitializeComponent();
}
public static byte[] ImageToBinary(string imagePath)
{
FileStream fS = new FileStream(imagePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
byte[] b = new byte[fS.Length];
fS.Read(b, 0, (int)fS.Length);
fS.Close();
return b;
}
static public string ToHex(byte[] bin_data)
{
string result = "";
foreach (byte ch in bin_data)
{
// 2자리의 16진수로 출력
result += string.Format("{0:x2}", ch);
}
return result;
}
private void button1_Click(object sender, EventArgs e)
{
Image img;
openFileDialog1.FileName = "";
openFileDialog1.Title = "Images";
openFileDialog1.Filter = "All Images|*.jpg; *.jpeg";
openFileDialog1.ShowDialog();
string filepath = @"파일경로";
if (System.IO.Directory.Exists(filepath))
{
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(filepath);
foreach (var item in di.GetFiles())
{
pictureBox1.ImageLocation = openFileDialog1.FileName.ToString();
var binary = ImageToBinary(openFileDialog1.FileName.ToString());
string resultHex = ToHex(binary);
//사번
empnum = Path.GetFileNameWithoutExtension(item.Name);
textBox2.Text = resultHex;
}
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void pictureBox2_Click(object sender, EventArgs e)
{
}
}
}
Comment 0
No. | Subject | Author | Date | Views |
---|---|---|---|---|
99 |
NaT NaN 관련 질문이요
[1] ![]() | solkim | 2022.07.11 | 40 |
98 | 포스 바코드 리더기 질문 [1] | 파이썬초보 | 2022.03.22 | 130 |
97 |
파이썬 그래프 관련 질문 드립니다.
[1] ![]() | 바른세상 | 2022.03.15 | 104 |
96 |
request.cookies.get이 안됩니다..
![]() | 권기원 | 2022.02.22 | 90 |
95 | 파이썬 정렬 기능 과 시각화 문의 드립니다. [1] | 바른세상 | 2022.02.18 | 112 |
94 | 파이썬 슬라이싱 [2] | 반말 | 2021.03.27 | 288 |
93 | c# 프로젝트 | hhe3522 | 2018.12.04 | 2617 |
92 | 다음 API 지도 데이터 추출 관련 문의 | 이대우1234567 | 2018.11.07 | 2508 |
91 | SQL 서버와 연결 후, 클라이언트 포트 클리어 방법 | 암무거나 | 2018.03.27 | 3614 |
90 | C#에서 MSSQL에 많은 데이터를 빠르게 넣을 수 있는 방법 | 코코라니 | 2018.03.17 | 5298 |
89 | 데이터 싱크 프로그램 제작 질문드립니다. | 베로 | 2017.11.09 | 4121 |
88 | VS Code 로 C# 개발할때.... | 1231234 | 2017.08.31 | 4859 |
87 | C++ 오류 | 베르사유 | 2017.08.10 | 4462 |
86 | EntityFramework 트랜잭션 어떻게 되는건지 궁금합니다 | 능능능 | 2017.08.09 | 4996 |
85 | 라이브러리 구동 샘플 프로그램 | 기타치는퐝동 | 2017.05.26 | 4219 |
84 | 깜빡임 효과 주는 방법 문의 [1] | 방자 | 2017.02.08 | 5878 |
83 | 인터넷 실행 | 후알유? | 2016.12.12 | 5749 |
82 | for문 사용방법 문의 [2] | 방자 | 2016.10.27 | 6699 |
» | FileStream 사용 시 오류사항 문의 | Lauren | 2016.09.01 | 6257 |
80 | 웹응용프로그램 프로젝트 열기 문의 | hoonsik.kong | 2016.06.13 | 7461 |