Why am I not able to save JPEG images read using the URLREAD function?

1 view (last 30 days)
I am attempting to save a JPEG image that I read using the URLREAD function. I am saving the file using the following code:
url = '<URL to JPEG Image>';
[imd, status] = urlread(url);
fd = fopen('image.jpg', 'w');
fwrite(fd, imd, 'uint8');
fclose(fd);
When I attempt to open the saved image ("image.jpg"), I do not see the image. Depending on the software used to view the image, it may appear as a black square, or an error message might appear informing me that the image is not in a valid format.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This bug has been fixed in MATLAB R14SP3. This issue has been fixed by adding a new functionality called URLWRITE, which saves the data in the format needed. Here is an example:
urlwrite('url to JPEG image','image.jpg')
For more information on URLWRITE, please see in the MATLAB documentation by typing following at the MATLAB command prompt:
doc urlwrite
For previous product releases:
There is a bug in MATLAB 6.5 (R13) in the way that URLREAD interprets binary data.
There are no workarounds.

More Answers (0)

Categories

Find more on Install Products in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!