Visual_Basic 板


LINE

※ 引述《pkyu (锅盖)》之铭言: : 请输入专案类型(网站专案或者应用程式专案): : 因为工作遇到的问题 所以跟各位请教一下 : 相机(工业用的品检机)连接到PC 使用VB.NET 2005 exprese : 厂商的软体本身已经有vb模组可使用 : 相机有800*600 模式 : 可是我VB做的框没办法这麽大,我该如何裁剪掉呢 : EX : ___________ ________ : | | | | : | | | | : | | ---> | | : | | |________| : |___________| : 5*5 4*4 : 实际大小 VB拉的范围 : 虽说显示会自己切掉,但是当用内建存图,会抓超过vb拉的范围 : 问题一、如何将照下来的照片裁成自己想要的大小? Function ClipImage(ByVal img As Image, ByVal r As Rectangle) As Image Dim bmp As New Bitmap(r.Width, r.Height) Dim g As Graphics = Graphics.FromImage(bmp) g.DrawImage(img, New Point(-r.X, -r.Y)) g.Dispose() Return bmp End Function 使用范例: Dim img As Image = Image.FromFile("d:\test.bmp") Dim img2 As Image = ClipImage(img, New Rectangle(10, 10, 200, 200)) img2.Save("d:\test_clip.bmp") : 问题二、如果我要再影像上加上辅助框该怎做?(类似样品的定位点) 从Image建立Graphics,使用到Graphics.FromImage: Shared Function FromImage(ByVal image As Image) As Graphics 接着在用Graphics.DrawRectangle: Sub DrawRectangle(ByVal pen As Pen, ByVal rect As Rectangle) 画出矩形,范例如下: Dim img As Image = Image.FromFile("d:\test.bmp") Using g As Graphics = Graphics.FromImage(img) g.DrawRectangle(Pens.Black, _ New Rectangle(0, 0, img.Width - 1, img.Height - 1)) End Using img.Save("d:\test_rect.bmp") : 问题三、该怎麽将影像中的座标点提取颜色出来判断? 先用你的Image建立Bitmap,使用Bitmap.New: Sub New(ByVal original As Image) 接着使用Bitmap.GetPixel、Bitmap.SetPixel: Sub SetPixel(ByVal x As Integer, ByVal y As Integer, _ ByVal color As Color) Function GetPixel(ByVal x As Integer, ByVal y As Integer) As Color 使用范例: Dim img As Image = Image.FromFile("d:\test.bmp") Dim bmp As New Bitmap(img) For i As Integer = 0 To bmp.Width - 1 For j As Integer = 0 To bmp.Height - 1 Dim c As Color = bmp.GetPixel(i, j) Dim _c As Color = Color.FromArgb(c.A / 2, _ c.R / 2, _ c.G / 2, _ c.B / 2) bmp.SetPixel(i, j, _c) Next Next bmp.Save("d:\test_handle.bmp") : 麻烦懂的人提点提点(因为刚接触VB,工作又有点赶) : 我会很感谢大家的 --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.164.82.202







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Gossiping站内搜寻

TOP