动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   .Net → 阅读文章

 将一个图片按比例缩放显示在一个Frame中

作者来源: 
阅读 1878 人次 , 2006-3-29 4:35:00 

代码如下:

'form1.frm
version 5.00
object = "{f9043c88-f6f2-101a-a3c9-08002b2f49fb}#1.2#0"; "comdlg32.ocx"
begin vb.form form1
caption = "form1"
clientheight = 5010
clientleft = 60
clienttop = 345
clientwidth = 7800
linktopic = "form1"
scaleheight = 334
scalemode = 3 'pixel
scalewidth = 520
startupposition = 3 '窗口缺省
begin mscomdlg.commondialog commondialog1
left = 4635
top = 3120
_extentx = 847
_extenty = 847
_version = 393216
end
begin vb.frame frame1
caption = "frame1"
height = 3000
left = 4500
tabindex = 2
top = 30
width = 3180
begin vb.picturebox picture2
appearance = 0 'flat
forecolor = &h80000008&
height = 2625
left = 120
scaleheight = 173
scalemode = 3 'pixel
scalewidth = 194
tabindex = 3
top = 255
width = 2940
begin vb.image image1
height = 1575
left = 465
top = 390
width = 1965
end
end
end
begin vb.commandbutton command1
caption = "&load picture"
height = 330
left = 5400
tabindex = 0
top = 3150
width = 1425
end
begin vb.picturebox picture1
appearance = 0 'flat
autosize = -1 'true
borderstyle = 0 'none
forecolor = &h80000008&
height = 4425
left = 60
scaleheight = 4425
scalewidth = 4380
tabindex = 1
top = 105
width = 4380
end
end
attribute vb_name = "form1"
attribute vb_globalnamespace = false
attribute vb_creatable = false
attribute vb_predeclaredid = true
attribute vb_exposed = false
option explicit

dim returnheight as long, returnwidth as long

private sub command1_click()
dim bigwidth as long, bigheight as long
dim stretchwidth as long, stretchheight as long
commondialog1.filter = "jpeg文件|*.jpg|gif文件|*.gif|所有文件|*.*"
commondialog1.showopen
if commondialog1.filename <> "" then
picture1.picture = loadpicture(commondialog1.filename)

bigwidth = picture1.width
bigheight = picture1.height
stretchwidth = picture2.scalewidth
stretchheight = picture2.scaleheight

stretchimage bigwidth, bigheight, stretchwidth, stretchheight, true

image1.stretch = true
image1.width = returnwidth
image1.height = returnheight

image1.left = (picture2.scalewidth - image1.width) / 2
image1.top = (picture2.scaleheight - image1.height) / 2
image1.picture = loadpicture(commondialog1.filename)
end if
end sub

private sub stretchimage(originalwidth as long, originalheight as long, stretchwidth as long, stretchheight as long, optional flag as boolean = false)
if (originalwidth >= stretchwidth or originalheight > stretchheight) or flag = true then '需要缩放
if originalwidth / originalheight >= stretchwidth / stretchheight then
returnwidth = stretchwidth
returnheight = stretchwidth / originalwidth * originalheight
else
returnheight = stretchheight
returnwidth = stretchheight / originalheight * originalwidth
end if
else
returnheight = originalheight
returnwidth = originalwidth
end if
end sub

 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:.Net在SqlServer中的图片存取技术
· 下一篇:多层结构来开发ASP.NET程序
· 用ASP.NET动态生成图像(转2)
· 一、Servlet和JSP概述
· ListItem Web 控件
· .Net边学边讲(一)
· ASP.net随机数应用实例


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077