Matlab中使用Java api繪圖圖形並儲存為jpeg格式,matlabjpeg
直接上代碼:
close all;import java.io.*;import java.awt.*;import java.awt.image.BufferedImage;import java.awt.image.BufferedImage.*;import javax.imageio.ImageIO;h = 700;w = 500;image = BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); graphics = image.getGraphics(); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);%對指定的矩形地區填充顏色graphics.setColor(Color.WHITE); %GREEN:綠色; 紅色:RED; 灰色:GRAYgraphics.fillRect(0, 0, w, h);%對指定的矩形地區填充顏色graphics.setColor(Color.WHITE);graphics.fillRect(240, 0, 240, 720);graphics.setColor(Color.BLACK);%畫直線x=100,y=100,x1=150,y1=y + 200; graphics.drawLine(x,y,x+x1,y1); %多邊形xPoints = [90,100,250,250];yPoints = [180,150,150,180]; graphics.drawPolyline(xPoints, yPoints, 4);%橢圓xOval=100,yOval=360; graphics.drawOval(xOval, yOval, 150, 130); %文字graphics.drawString('直線',100+50,100-5); graphics.dispose(); ImageIO.write(image,'JPEG', File('testx.jpg'));img = imread('testx.jpg');imshow(img);
matlab映像儲存為jpeg格式
嗯,經常會有這種問題,你不要儲存成FIG格式。圖在MATLAB裡面畫出來以後,圖上面有一排工具列,直接選擇EDIT裡面的“Copy figure“,就可以COPY到任何文檔裡面了,比如WORD,PPT。
如果真要先另存出來,你就直接存成JPEG格式,省事。
matlab中 GUI axes中的映像儲存為jpeg儲存映像不完整
儲存映像,試試這個代碼:
[filename pathname]=uiputfile({'*.jpeg','jpeg file(*.jpeg)');
str = [pathname filename];
strBefore = str(1:end-4);
strEx = str(end-3 : end);
figure('visible', 'off');
strcmp(strEx, '.jpeg')
fullName = [strBefore,'.jpeg'];
h=get(handles.axes1,'children');
figure('visible','off');
axes;
copyobj(h,gca)
print(gcf,'-dmeta',fullName)