图像自适应窗口显示,以窗口中心为基准

read_image (Image, 'C:/Users/Administrator/Desktop/图片/1.png')
dev_clear_window ()
dev_display (Image)
winWith:=1000
winHeiht:=880

*设置图形窗口中要显示图像的部分*
dev_resize_window_fit_size (0, 0, winWith, winHeiht, -1, -1)
get_image_size (Image, imageWidth, imageHeight)
ScaleWith:=imageWidth/(winWith*1.0)
ScaleHiht:=imageHeight/(winHeiht*1.0)
if (ScaleWith>=ScaleHiht)
*更宽。这种情况下Y向就要偏移,X向0坐标*
row1:=((imageHeight-winHeiht*ScaleWith)*1.0)/2
col1:=0
*结束坐标为起始+缩放后的图像长度*
row2:=row1+winHeiht*ScaleWith
col2:=col1+winWith*ScaleWith
else
*更宽。这种情况下Y向就要偏移,X向0坐标*
row1:=0
col1:=((imageWidth-winWith*ScaleHiht)*1.0)/2
*结束坐标为起始+缩放后的图像长度*
row2:=row1+winHeiht*ScaleHiht
col2:=col1+winWith*ScaleHiht
endif
if (ScaleWith==ScaleHiht)
row1:=(imageHeight*1.0)/2
col1:=(imageWidth*1.0)/2
row2:=imageHeight
col1:=imageHeight
endif
dev_clear_window ()
dev_set_part (row1, col1, row2, col2)
dev_display (Image)

posted @ 2022-08-29 11:41  奔腾的岩浆  阅读(35)  评论(0编辑  收藏  举报