Bạn có thể làm điều đó với sự trợ giúp của Java. Ví dụ:
% get a stream of bytes representing an endcoded JPEG image
% (in your case you have this by decoding the base64 string)
fid = fopen('test.jpg', 'rb');
b = fread(fid, Inf, '*uint8');
fclose(fid);
% decode image stream using Java
jImg = javax.imageio.ImageIO.read(java.io.ByteArrayInputStream(b));
h = jImg.getHeight;
w = jImg.getWidth;
% convert Java Image to MATLAB image
p = reshape(typecast(jImg.getData.getDataStorage, 'uint8'), [3,w,h]);
img = cat(3, ...
transpose(reshape(p(3,:,:), [w,h])), ...
transpose(reshape(p(2,:,:), [w,h])), ...
transpose(reshape(p(1,:,:), [w,h])));
% check results against directly reading the image using IMREAD
img2 = imread('test.jpg');
assert(isequal(img,img2))
Phần đầu tiên của giải mã dòng byte JPEG được dựa trên câu trả lời này:
JPEG decoding when data is given in array
Phần cuối cùng chuyển đổi hình ảnh Java để MATLAB dựa trên giải pháp này trang:
How can I convert a "Java Image" object into a MATLAB image matrix?
Đó phần cuối cùng cũng có thể được viết lại như sau:
p = typecast(jImg.getData.getDataStorage, 'uint8');
img = permute(reshape(p, [3 w h]), [3 2 1]);
img = img(:,:,[3 2 1]);
imshow(img)
Cảm ơn, hoạt động trơn tru! – kahlo