• 카테고리

    질문 & 답변
  • 세부 분야

    프론트엔드

  • 해결 여부

    미해결

binary Type을 이미지로 그리기

20.05.19 19:52 작성 조회수 762

1

서버에서 이미지파일을 binary 형태의 response로 받았습니다. 
이 binary reponse를 view 에서 변형하여 이미지로 나타내려고 합니다. 

newMark2 () {
// 이진문자열 => this.GET_FETCHED_SCARIMG
let binary = ''
const responseText = this.GET_FETCHED_SCARIMG
const responseTextLen = this.GET_FETCHED_SCARIMG.length
for (let i = 0; i < responseTextLen; i++) {
binary += String.fromCharCode(responseText.charCodeAt(i) & 255)
}
const newDarn = 'data:image/png;base64,' + btoa(binary)
document.getElementById('tts2').src = newDarn
}

이진문자열을 서버에서 받을 때 request header에 content type을 설정해줘야할까요? 
뭐가 문제인지 모르겠습니다. 

답변 1

답변을 작성해보세요.

0

안녕하세요 영찬님, 말씀해주신 바이너리 데이터를 이미지로 표시하는 방법 관련해서는 아래 링크 참고해보시면 좋을 것 같습니다. 호출하는 백엔드 API 정보나 현재 구현하고 계시는 상황이 정확히 어떤건지 몰라서 구체적으로 답변 해드리기가 어려울 것 같아요..! 강의 수강해주셔서 감사합니다 :)

https://stackoverflow.com/questions/14915058/how-to-display-binary-data-as-image-extjs-4