WindowAPI(http://www.mathworks.com/matlabcentral/fileexchange/31437)を使用して、matlabで黒いフルスクリーンを表示しています。画面に描画する場合、line()およびrectangle()関数を使用した描画は非常に遅いことがわかります。
matlabのメカニズムを使用せずにピクセルの値を設定するにはどうすればよいですか?たとえば、ウィンドウのキャンバスを取得するのは素晴らしいことです。
WindowAPI(http://www.mathworks.com/matlabcentral/fileexchange/31437)を使用して、matlabで黒いフルスクリーンを表示しています。画面に描画する場合、line()およびrectangle()関数を使用した描画は非常に遅いことがわかります。
matlabのメカニズムを使用せずにピクセルの値を設定するにはどうすればよいですか?たとえば、ウィンドウのキャンバスを取得するのは素晴らしいことです。
「キャンバス」を模倣する 1 つの方法は、MATLAB イメージを使用することです。アイデアは、そのピクセルを手動で変更し'CData'
、プロットされた画像を更新することです。
画面サイズと同じサイズの画像を使用できますが (画像のピクセルは画面のピクセルと 1 対 1 で対応します)、更新に時間がかかることに注意してください。秘訣は、サイズを小さく保ち、MATLAB にフルスクリーン全体にマップさせることです。そうすれば、画像は「太い」ピクセルを持っていると考えることができます。もちろん、画像の解像度は、描画するマーカーのサイズに影響します。
説明のために、次の実装を検討してください。
function draw_buffer()
%# paramters (image width/height and the indexed colormap)
IMG_W = 50; %# preferably same aspect ratio as your screen resolution
IMG_H = 32;
CMAP = [0 0 0 ; lines(7)]; %# first color is black background
%# create buffer (image of super-pixels)
%# bigger matrix gives better resolution, but slower to update
%# indexed image is faster to update than truecolor
img = ones(IMG_H,IMG_W);
%# create fullscreen figure
hFig = figure('Menu','none', 'Pointer','crosshair', 'DoubleBuffer','on');
WindowAPI(hFig, 'Position','full');
%# setup axis, and set the colormap
hAx = axes('Color','k', 'XLim',[0 IMG_W]+0.5, 'YLim',[0 IMG_H]+0.5, ...
'Units','normalized', 'Position',[0 0 1 1]);
colormap(hAx, CMAP)
%# display image (pixels are centered around xdata/ydata)
hImg = image('XData',1:IMG_W, 'YData',1:IMG_H, ...
'CData',img, 'CDataMapping','direct');
%# hook-up mouse button-down event
set(hFig, 'WindowButtonDownFcn',@mouseDown)
function mouseDown(o,e)
%# convert point from axes coordinates to image pixel coordinates
p = get(hAx,'CurrentPoint');
x = round(p(1,1)); y = round(p(1,2));
%# random index in colormap
clr = randi([2 size(CMAP,1)]); %# skip first color (black)
%# mark point inside buffer with specified color
img(y,x) = clr;
%# update image
set(hImg, 'CData',img)
drawnow
end
end