function BMPReader(strPathName) fFile = fopen(strPathName, 'rb'); [data, count] = fread(fFile); %offset nOffset = 0; for i = 1:4 nOffset = nOffset + bitshift(data(10+i), (i-1)*8); end %width nWidth = 0; for i = 1:4 nWidth = nWidth + bitshift(data(18+i), (i-1)*8); end %height nHeight = 0; for i = 1:4 nHeight = nHeight + bitshift(data(22+i), (i-1)*8); end %bit count nBitCount = data(29) + bitshift(data(30), 8); %bmp格式存储是从图片的下到上 img = zeros(nHeight, nWidth); img = reshape(data(nOffset+1:end), nWidth, nHeight); img = flipud(img'); %先转置,然后上下交换 imshow(img, [0, 255]); %close file fclose(fFile);
matlab读取bmp 二进制,Matlab读取BMP文件代码
最新推荐文章于 2022-03-16 22:24:07 发布