查找Richtextbox图像的宽度和高度 [英] Find Richtextbox image width and height

查看:91
本文介绍了查找Richtextbox图像的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 {\rtf1\ansi\deff0\deftab720 
{\ pict \wmetafile8 \ picw557 \ pich762 \ picscalex99 \ picscaley98 \ picwgoal316 \pichgoal436
010009000003260100000200170000000000050000000B0200000000050000000C02FA022D0203
0000001E00050000000C0202032F02050000000B0200000000030000001E00050000000C020203
2F02050000000B0200000000050000000B0200000000030000001E00050000000C020603320205
0000000B0200000000050000000B0200000000050000000B0200000000030000001E0005000000
0C0208033402050000000B0200000000050000000B0200000000050000000B0200000000050000
000B0200000000030000001E00050000000902000000000400000002010100050000000102FFFF
FF00040000002E01180005000000310201000000050000000C02C0020002050000000B02000000
00050000000B0200000000050000000B0200000000050000000B0200000000050000000B020000
00001200000026060F001A00FFFFFFFF000010000000C0FFFFFFC0FFFFFFC0010000800200000B
00000026060F000C004D61746854797065000080001000 0000FB02C0FD00000000000090010000
00020002001053796D626F6C0002040000002D01000008000000320A4A02400001000000F20017
00000026060F0024004D617468547970655555180003010103000A010315000001000B11110D02
862B220000000A00000026060F000A00FFFFFFFF01000000000010000000FB0210000700000000
00BC02000000000102022253797374656D0000040000002D01010004000000F001000004000000
2701FFFF040000002701FFFF040000002701FFFF040000002701FFFF040000002701FFFF030000
<跨度类= 代码位> 000000
} }





pich762 - 身高

picw557 - 宽度



但这里有762,557 \ pichN,\ picWN格式,但实际图像是小图像,但我得到762,557是非常大的图像。我需要这个图像的实际宽度和高度。这不是在WPF中。我只需要普通窗口表格。

解决方案

RTF中的内容 picw pich tags是文档中图像的实际宽度和高度,以像素为单位。它不是显示的宽度和高度。那些显示在 picwgoal pichgoal 标签中。然后它们之后的数字是所需的显示尺寸,但是是缇,而不是像素。哦,这些值被指定为Long,而不是整数。



你可以在RTF标签上找到doucmentation

此处 [ ^ ]。



.NET中不支持twips扩展。您可以使用以下函数将缇转换为当前显示设备上的像素,使用它的DPI设置:

私有函数ConvertTwipsToPixel(ByVal lngTwips为Long,ByVal blnHorizo​​ntal As Boolean)As Long 
Const TWIPSPERINCH As Long = 1440
Dim gr As Graphics
gr = Me.CreateGraphics
if blnHorizo​​ntal Then
ConvertTwipsToPixel = CLng(lngTwips / TWIPSPERINCH * gr.DpiX)
其他
ConvertTwipsToPixel = CLng(lngTwips / TWIPSPERINCH * gr.DpiY)
结束如果
结束函数



此代码取自 http://vbcity.com/forums/t/5030.aspx [ ^ ],尚未经过测试。


{\rtf1\ansi\deff0\deftab720
{\pict\wmetafile8\picw557\pich762\picscalex99\picscaley98\picwgoal316\pichgoal436
010009000003260100000200170000000000050000000B0200000000050000000C02FA022D0203
0000001E00050000000C0202032F02050000000B0200000000030000001E00050000000C020203
2F02050000000B0200000000050000000B0200000000030000001E00050000000C020603320205
0000000B0200000000050000000B0200000000050000000B0200000000030000001E0005000000
0C0208033402050000000B0200000000050000000B0200000000050000000B0200000000050000
000B0200000000030000001E00050000000902000000000400000002010100050000000102FFFF
FF00040000002E01180005000000310201000000050000000C02C0020002050000000B02000000
00050000000B0200000000050000000B0200000000050000000B0200000000050000000B020000
00001200000026060F001A00FFFFFFFF000010000000C0FFFFFFC0FFFFFFC0010000800200000B
00000026060F000C004D617468547970650000800010000000FB02C0FD00000000000090010000
00020002001053796D626F6C0002040000002D01000008000000320A4A02400001000000F20017
00000026060F0024004D617468547970655555180003010103000A010315000001000B11110D02
862B220000000A00000026060F000A00FFFFFFFF01000000000010000000FB0210000700000000
00BC02000000000102022253797374656D0000040000002D01010004000000F001000004000000
2701FFFF040000002701FFFF040000002701FFFF040000002701FFFF040000002701FFFF030000
000000
}}



pich762--height
picw557--width

but here 762,557 \pichN,\picWN format but actual image is small image but i am getting 762,557 is very big image. I need the actual width and height of this image. This is Not in WPF. I need Normal Window Form only.

解决方案

What''s in the RTF picw and pich tags is the actual width and height of the image in the document in pixels. It''s not the displayed width and height. Those show up in the picwgoal and pichgoal tags. Then numbers after them are the desired display size but in twips, not pixels. Oh, and those values are specified as Long, not Integer.

You can find doucmentation on RTF tags
here[^].

There is no support for twips scaling in .NET. You can use the following function to convert twips to pixels on the current display device using it''s DPI settings:

Private Function ConvertTwipsToPixel(ByVal lngTwips As Long, ByVal blnHorizontal As Boolean) As Long
    Const TWIPSPERINCH As Long = 1440
    Dim gr As Graphics
    gr = Me.CreateGraphics
    If blnHorizontal Then
        ConvertTwipsToPixel = CLng(lngTwips / TWIPSPERINCH * gr.DpiX)
    Else
        ConvertTwipsToPixel = CLng(lngTwips / TWIPSPERINCH * gr.DpiY)
    End If
End Function


This code was lifted from http://vbcity.com/forums/t/5030.aspx[^], and has NOT been tested.


这篇关于查找Richtextbox图像的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆