2016-10-18 4 views
0

텍스트 :자 마린 안드로이드 - 이미지는이 코드를 발견

// provide read access to the file 
FileStream fs = new FileStream(media.Path, FileMode.Open,FileAccess.Read); 
// Create a byte array of file stream length 
byte[] ImageData = new byte[fs.Length]; 
//Read block of bytes from stream into the byte array 
fs.Read(ImageData,0,System.Convert.ToInt32(fs.Length)); 
//Close the File Stream 
fs.Close(); 
string _base64String = Convert.ToBase64String (ImageData); 

나는 이미지를 전달하고있는 수입이 작업을 진행하게 사용하는 방법을 모르겠어요. 기본적으로 이미지를 가져 와서 텍스트로 변환하려고합니다.

감사

+0

으로

byte[] ImageData = File.ReadAllBytes(@"Path to the image to load"); string _base64String = Convert.ToBase64String(ImageData); 

"이미지를 가져 와서 텍스트로 변환 하시겠습니까?" 이미지의 텍스트를 읽는 것을 의미합니까? 그렇게하는 것은 여기있는 것보다 훨씬 더 복잡합니다. – EJoshuaS

+0

아니요, 이미지를 텍스트로 변환해야 데이터베이스에 저장할 수 있습니다. –

+0

첫 번째 인수 인 media.Path는 이미지에 대한 파일 경로입니다. – Jason

답변

2

은 내가 BLOB 파일에 이미지를 저장하는 것이 좋습니다. 당신이 정말로 문자열에 저장하려면 다음 코드를 문자열로

을 니펫으로하지만 당신은 그것을 달성 할 수 무슨 뜻 이죠 BYTEARRAY

byte[] data = Convert.FromBase64String(_base64String); 
     File.WriteAllBytes(@"Path to the image to store", data); 
+0

그것은 훌륭합니다. 예를 들어 DCIM에서 이미지를 어떻게 참조합니까? 그 모습의 경로는 무엇입니까? –

+0

System.Environment.GetFolderPath –

+0

죄송합니다. 다시 사용할 수 있습니다. 특정 디렉토리를 얻으려면 어떻게 사용합니까? 그래도 도와 ​​줘서 고마워. 나는 멍청한 사람이야. –