本帖最后由 张满满 于 2023-2-16 18:15 编辑
黑白图
黑白图
彩色图
- dev_update_off ()
- *****Gray图片写入Gray文字****
- read_image (Image, 'fabrik')
- overpaint_string (Image, '这是一条文字\r\n这是第二行\r\nNewLine', 0, 0, [1,155,6], 'mono',80)
- dev_display (Image)
- stop ()
- *****Gray图片写入RGB文字****
- read_image (Image, 'fabrik')
- cfa_to_rgb (Image, RGBImage, 'bayer_gb', 'bilinear')
- overpaint_string (RGBImage, '这是一条文字\r\n这是第二行\r\nNewLine', 200, 100, [255,0,0], 'mono', 30)
- dev_display (RGBImage)
- stop ()
- *****RGB图片写入RGB文字****
- read_image (Image, 'brycecanyon1')
- overpaint_string (Image, '这是一条文字\r\n这是第二行\r\nNewLine', 100, 100, [0,255,255], 'mono', 50)
- dev_display (Image)
- stop ()
- overpaint_string (Image, ' 5 5', 10, 10, [0,0,255], 'mono', 30)
- dev_display (Image)
复制代码
overpaint_string.hdvp
(4.23 KB, 下载次数: 20)
****内部代码*****
- try
- dev_update_off ()
- dev_set_color ('white')
- open_window (0, 0, 1, 1, 0, 'buffer', '', WindowHandleBuffer)
- set_tposition (WindowHandleBuffer, 1, 1)
- set_display_font (WindowHandleBuffer, FontSize, Font, 'false', 'false')
- count_channels (SrcImg, Channels)
- tuple_regexp_replace (Str, ['(^\\s*)|(\\s*$)','replace_all'], '', Str2)
- if (Str2='')
- return ()
- endif
- grayCount:= |GrayVal|
- if ((grayCount=1 and Channels=1) or (grayCount=3 and Channels=3))
- gray := GrayVal
- elseif (grayCount=3 and Channels=1)
- gray := 0.299 * GrayVal[0] + 0.587 * GrayVal[1] + 0.114 * GrayVal[2]
- elseif (grayCount=1 and Channels=3)
- gray := [GrayVal,GrayVal,GrayVal]
- else
- throw ('仅支持RGB及灰度图像')
- endif
- tuple_split (Str, ['\r\n'], Substrings)
- count:=|Substrings|
- fontCounts:=[]
- height:=0
- widths:=[]
- for Index1 := 0 to count-1 by 1
- get_string_extents (WindowHandleBuffer, Substrings[Index1], Ascent, Descent, Width, Height)
- height:=height+Height
- widths[Index1]:= Width
- endfor
- Max:=max(widths)
- set_window_extents (WindowHandleBuffer, 0, 0, Max*1.5, height*1.7)
- for Index := 0 to count-1 by 1
- write_string (WindowHandleBuffer, Substrings[Index])
- if (Index==count-1)
- break
- endif
- new_line (WindowHandleBuffer)
- endfor
- dump_window_image (strImg, WindowHandleBuffer)
- rgb1_to_gray (strImg, GrayImage)
- binary_threshold (GrayImage, Region, 'max_separability', 'light', UsedThreshold)
- smallest_rectangle1 (Region, Row1, Column1, Row2, Column2)
- move_region (Region, RegionMoved, Row-2, Col-2)
- overpaint_region (SrcImg, RegionMoved, gray, 'fill')
- close_window (WindowHandleBuffer)
- catch (Exception)
- throw (Exception)
- endtry
- return ()
复制代码 希望对大家有所帮助
|