如何获得一个图片文件的宽度和高度,……

litaoa 2002-04-09 02:47:52
我用image控件image=loadpicture(****)加载图片,我用msgbox image.Height 和
msgbox image.Width得到的图片大小和我用其它工具得到不一样,我该怎么才能得到它的大小,谢谢了,
...全文
166 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
litaoa 2002-04-10
  • 打赏
  • 举报
回复
谢谢大家了我还是用pic控件的方法吧…对我来说比较简单…
uguess 2002-04-09
  • 打赏
  • 举报
回复

试试这个程序!

'The Bitmap Info project demonstrates one means of obtaining from a bitmap file on the disk its image information without loading the actual bitmap.
'
'Within a bitmap file are 2 header groupings of information describing the bitmap image in that file. This data is contained in the file's BITMAPFILEHEADER and BITMAPINFOHEADER structures. By using the VB Type to recreate these structures, the details of the bitmap contained in the file can be obtained with a simple binary read of this data.
'(Note: due to the formatting of the code to allow pasting into VB, the strings used here will necessitate horizontal scrolling of the browser window on displays under 1024x768 full screen.)
'
'
' Form Code
'
'To a form add the controls as indicated in the illustration. To see a template of this form with control names substituted for the control captions, click here to open the image in a new window.
'
'The names of the description labels is unimportant, but the data returned from the routine below posts the information to the lblInfo() label array. Also on the form is an image control (Image1), with its Stretch property set to True, two command buttons (cmdSelect and cmdEnd), and another label to contain the selected filename and path (lblFileName). Finally, the routine needs a common dialog control (CMDialog1) added to the form.
'
'Paste the following code into the general declarations section of the form:

'--------------------------------------------------------------------------------

Option Explicit

Private Const CANCELERR = 32755
Private Const BI_RGB = 0&
Private Const BI_RLE8 = 1&
Private Const BI_RLE4 = 2&
Private Const BI_BITFIELDS = 3&

Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type

Private Type BITMAPFILEHEADER
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type


Private Sub Form_Load()

'initialize the form controls
lblFileName = "Select a bitmap or RLE file to detail..."
lblInfo(0) = ""
lblInfo(1) = ""
lblInfo(2) = ""
lblInfo(3) = ""
lblInfo(4) = ""
lblInfo(5) = ""
lblInfo(6) = ""
lblInfo(7) = ""

'position the form
Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2

End Sub


Private Sub cmdEnd_Click()

Unload Me

End Sub


Private Sub cmdSelect_Click()

'create some working variables
Dim ff As Integer
Dim tmp As String

'create the variables to hold the bitmap info
Dim FileHeader As BITMAPFILEHEADER
Dim InfoHeader As BITMAPINFOHEADER

On Error GoTo cmdSelect_FileErrorHandler

'show the common dialog
CMDialog1.CancelError = True
CMDialog1.ShowOpen

'display a rendition of the loaded bitmap
Image1 = LoadPicture((CMDialog1.filename))
Image1.ZOrder 1

'read the file header info
ff = FreeFile
Open CMDialog1.filename For Binary Access Read As #ff
Get #ff, , FileHeader
Get #ff, , InfoHeader
Close #ff

'display the file info
lblFileName = CMDialog1.filename

lblInfo(0) = InfoHeader.biWidth & " pixels"
lblInfo(1) = InfoHeader.biHeight & " pixels"

'select the appropriate string based on the value of biCompression
Select Case InfoHeader.biSizeImage
Case 0: tmp$ = "BI_RGB bitmap; size variable not filled in."
Case Else: tmp$ = Format$(InfoHeader.biSizeImage, "#,###,###") & " bytes"
End Select
lblInfo(2) = tmp$

lblInfo(3) = InfoHeader.biPlanes
lblInfo(4) = InfoHeader.biBitCount & " (" & 2 ^ InfoHeader.biBitCount & " colours)"

'select the appropriate string based on the value of biCompression
Select Case InfoHeader.biCompression
Case BI_RGB: tmp$ = "Uncompressed bitmap."
Case BI_RLE8: tmp$ = "Run-length encoded (RLE) format for bitmaps with 8 bits per pixel."
Case BI_RLE4: tmp$ = "Run-length encoded (RLE) format for bitmaps with 4 bits per pixel."
Case BI_BITFIELDS: tmp$ = "Uncompressed 16- or 32-bit-per-pixel format."
End Select
lblInfo(5) = tmp$

'select the appropriate string based on the value of biClrUsed
Select Case InfoHeader.biClrUsed
Case 0:
tmp$ = "Bitmap uses the maximum number of colours corresponding to the"
tmp$ = tmp$ & " bits-per-pixel for the compression mode."

Case Is <> 0 And InfoHeader.biBitCount = 16:
tmp$ = "The size of the colour table used to optimize performance"
tmp$ = tmp$ & "of Windows colour palettes is " & Str$(InfoHeader.biClrUsed)
End Select
lblInfo(6) = tmp$

'select the appropriate string based on the value of biClrImportant
Select Case InfoHeader.biClrImportant
Case 0:
tmp$ = "All " & 2 ^ InfoHeader.biBitCount & " colour"
tmp$ = tmp$ & " indices are considered important for displaying this bitmap."
Case Is <> 0
tmp$ = "The number of colours that are considered important for displaying"
tmp$ = tmp$ & " this bitmap are " & Str$(InfoHeader.biClrImportant)
End Select
lblInfo(7) = tmp$

Exit Sub

'handle file errors or the user choosing cancel
cmdSelect_FileErrorHandler:

If Err <> CANCELERR Then MsgBox Error$(Err), 48, "Image Info"
lblFileName = "No file was selected."

End Sub
寒雪叔叔 2002-04-09
  • 打赏
  • 举报
回复
如果知道这个文件的格式就好办了
比如为bmp格式,只要读出这个文件的文件头就行了,
先读一个BITMAPFILEHEADER,再读一个别BITMAPINFOHEADER
这个图形的宽高就在这个BITMAPINFOHEADER里面了。其它的格式方法差不多
stormday 2002-04-09
  • 打赏
  • 举报
回复
用Picture控件,AutoSize=True.
访问它的Height和Width属性,获得高与宽。
为了美观,可以将它的Visible属性设为不可见。
playyuer 2002-04-09
  • 打赏
  • 举报
回复
MsgBox "Size: " & form1.ScaleX(p.Width,8,3) & " × " & form1.ScaleY(p.Height,8,3)

如何正确得出 Picture 的宽、高的像素数????
http://www.csdn.net/Expert/TopicView1.asp?id=258476
gump2000 2002-04-09
  • 打赏
  • 举报
回复
用pictureBox控件
AutoSize=True
就可以了
另外
scalemode=3(pixel)
msgbox pic1.scalewidth & ":" & pic1.scaleheight
就识了
提供基于TCP/IP网络的即时消息传送、消息广播、实时聊天、文件传输等功能。 具体列举如下: ? 支持多账号 ? 可以同时发送同一个消息给多人,通过输入这些人的号码列表或姓名列表 ? 可以同时发送一个消息给所有好友 ? 有权限的人可以向所有用户发送“消息广播”,便于消息的发布 ? 即使用户不在线,也能通过服务器发送离线消息 ? 提供消息、聊天的历史记录,方便对信息的查看和管理 ? 提供查看在线的人的功能 ? 提供按ID或姓名查找用户的功能,添加用户方便 ? 小窗口显示,不占用屏幕很大的空间, ? 支持热键调出后台的应用程序。 ? 应用程序运行后,在任务栏右边生成一个图标,单击弹出在线状态 菜单,双击显示应用程序窗口,右击弹出主菜单。 ? 支持隐身登陆,可以看到在线的朋友,朋友却不知道你上线了 ? 可以实时显示用户的状态和随时改变自己的状态 ? 提供了自动弹出消息 ? 好友上线通知 ? 好友下线更新 ? 有权限的人可以发系统广播(或在服务器上发) ? 查看好友信息 ? 按姓名或号码查找某人 ? 在好友列表中删除某人 ? 可以选择在某人的好友中删除自己 ? 更改个人信息 ? 系统设置 ? 给在线好友传文件 ? 消息管理器 ? 在程序中设定最大,最小窗口尺寸(宽度高度) ? 主窗口总是浮在最上端 ? 速度快,占用资源少 论文简介 目录 第 1 章 概论 §1.1 课题的来源及意义 …………………………………………… 1 §1.2 网上寻呼的软件的现况……………………………………… 1 §1.3 面向对象方法与设计简介…………………………………… 2 §1.4 本章小结………………………………………………………… 3 第 2 章 网络通讯程序的设计原理和过程 §2.1 TCP/IP协议 …………………………………………………… 4 §2.2 客户/服务器程序的设计 …………………………………… 6 第 3 章 软件功能与界面需求…………………………………………… 9 第 4 章 概要设计和详细设计 §4.1总体设计概述……………………………………………………10 §4.2服务器数据库的设计 …………………………………………11 §4.3类设计的总体结构 ……………………………………………13 §4.4服务器端的常量定义 …………………………………………15 §4.5客户端的常量定义 ……………………………………………17 §4.6服务器端的底层通讯类的设计………………………………21 §4.7客户端的底层通讯类的设计…………………………………23 §4.8客户/服务器之间的通讯的数据类的设计 ………………25 §4.9发送数据的确认消息的编码方案 …………………………30 §4.10服务器端的分配用户帐号的策略…………………………31 §4.11 服务器的应用程序类CServerApp的设计 ……………31 §4.12 客户端的应用程序类CClientApp的设计 ……………33 §4.13服务器端检查用户是否仍然在线的算法 ………………34 §4.14服务器端处理用户请求的算法……………………………35 §4.15客户端处理服务器发送来数据的算法 …………………40 第 5 章 全文总结与工作展望 §5.1 全文总结…………………………………………………………42 §5.2 工作展望…………………………………………………………42 第 6 章 附录 §6.1 查错日志…………………………………………………………43 §6.2设计中遇到的问题 ……………………………………………46 参 考 文 献……………………………………………………………………47

7,785

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧