save with a specific size (32x32 pixels)

2 ビュー (過去 30 日間)
San May
San May 2020 年 12 月 24 日
コメント済み: Image Analyst 2020 年 12 月 28 日
How can I set a specific size for figure result?
Is there any rule to calculate the whole size of image?
When I use this,
fig1 = figure('Renderer', 'painters', 'Position', [10 10 164 164]);
The size I want is 32x32 pixels.

回答 (1 件)

Image Analyst
Image Analyst 2020 年 12 月 24 日
Try exportgraphics followed by imresize():
fig1 = figure('Renderer', 'painters');
plot(1:10, 'b-', 'LineWidth', 3);
% Create a temporary filename.
fileName = 'Delete Me.png';
exportgraphics(gcf, fileName);
close(fig1);
% read in temporary image.
rgbImage = imread(fileName);
% Resize to 32x32
image32 = imresize(rgbImage, [32, 32]);
figure
subplot(1, 2, 1);
imshow(rgbImage)
title('Full Size Version', 'FontSize', 20);
subplot(1, 2, 2);
imshow(image32)
title('32-by-32 Size Version', 'FontSize', 20);
% Delete temporary image.
recycle on;
delete(fileName);
g = gcf;
g.WindowState = 'maximized';
  1 件のコメント
Image Analyst
Image Analyst 2020 年 12 月 28 日
San, isn't this what you wanted? Why do you not approve of this code?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeRead, Write, and Modify Image についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by