필터 지우기
필터 지우기

How to convert image matrix to char stream?

조회 수: 2 (최근 30일)
Yuheng Huang
Yuheng Huang 2017년 7월 23일
댓글: Yuheng Huang 2017년 7월 26일
I want to POST an image to the server. I have a matrix read from file:
I = imread('file.jpg');%This line can't be changed
And what I do now is saving it to a file then read it back:
imwrite(I, 'temp.jpg');
fid = fopen('temp.jpg', 'r');
imgData = char(fread(fid)');
fclose(fid);
But when call this function frequently, there will be an error:
Unable to open file "temp.jpg" for writing. You might not have write permission.
Is there any solution to convert the matrix I to char stream imgData directly?

채택된 답변

Image Analyst
Image Analyst 2017년 7월 23일
What is your current folder? You're evidently not allowed to save the (badly-named) I there.
Or else you already have a file called that and some app has that file open and it's locked for modifying. If so, close it in the other app that has it open. If no other app has it open, then try
fclose('all');
before you call imwrite().
  댓글 수: 1
Yuheng Huang
Yuheng Huang 2017년 7월 26일
Is there any way to convert these two formats directly in the memory instead of saving on the disk and read back? I think this is a bit not elegant :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!