当前位置:网站首页>VB.net 简单的处理图片,黑白(类库——7)
VB.net 简单的处理图片,黑白(类库——7)
2022-07-04 04:58:00 【小虞163】
我们看,这一张图片使我们用手机拍的图片,不经过处理,打印出来就是灰的
在Photoshop里可以通过调整色阶,选择黑色的再选择白色的,就可以清晰化了
拍照时注意摊平,我这是扫描的彩色模式,作为测试
看VB.net如何处理
本文参考的csdn大佬的文章,vb.net 教程 5-15 图像处理之内存处理6就改了一个参数
import:
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
写函数:value可以自己调节,不一定只是180
''' <summary>
''' 图片黑白处理,记得使用多线程调用函数
''' </summary>
''' <param name="value">黑白数值常量,建议从128开始调,范围为0~255(byte)</param>
''' <param name="bmp">要处理的图片</param>
''' <returns>处理后的图片</returns>
Public Function BlackWhite(value As Byte, bmp As Bitmap)
Dim destImg As New Bitmap(bmp.Width, bmp.Height)
Dim sourceData As BitmapData = bmp.LockBits(New Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb)
Dim destData As BitmapData = destImg.LockBits(New Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb)
Dim pSource As IntPtr = sourceData.Scan0
Dim allBytes As Integer = sourceData.Stride * sourceData.Height
Dim rgbvalues() As Byte
ReDim rgbvalues(allBytes - 1)
Marshal.Copy(pSource, rgbvalues, 0, allBytes)
Dim pos As Integer = 0
Dim R, G, B As Integer
Dim avgValue As Integer
For j As Integer = 0 To sourceData.Height - 1
For i As Integer = 0 To sourceData.Width - 1
B = rgbvalues(pos)
G = rgbvalues(pos + 1)
R = rgbvalues(pos + 2)
avgValue = (B + G + R) / 3
If avgValue >= value Then avgValue = 255 Else avgValue = 0
rgbvalues(pos) = avgValue
rgbvalues(pos + 1) = avgValue
rgbvalues(pos + 2) = avgValue
pos += 3
Next
pos = pos + sourceData.Stride - sourceData.Width * 3
Next
Dim pDest As IntPtr = destData.Scan0
Marshal.Copy(rgbvalues, 0, pDest, allBytes)
bmp.UnlockBits(sourceData)
destImg.UnlockBits(destData)
Return destImg
End Function
调用:
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Pic.Image = GDI.BlackWhite(180, New Bitmap("C:\Users\Administrator\Desktop\example.jpg"))
End Sub
效果很好,可以去除一些褶皱,多余的背景
边栏推荐
- 【QT】制作MyComboBox点击事件
- Evolution of system architecture: differences and connections between SOA and microservice architecture
- Flink1.13 basic SQL syntax (II) join operation
- Automated testing selenium foundation -- webdriverapi
- [matlab] general function of communication signal modulation bandpass filter
- 补某视频网站的js,进行视频解密
- 【MATLAB】MATLAB 仿真模拟调制系统 — SSB 系统
- Rollup各组件作用
- The second case analysis of the breakthrough of defense system from the perspective of the red team
- cmake
猜你喜欢
Evolution of system architecture: differences and connections between SOA and microservice architecture
中科磐云—2022广东木马信息获取解析
光模块字母含义及参数简称大全
Simulated small root pile
TCP状态转换图
Detailed comparison of Hynix emmc5.0 and 5.1 series
Customize a pager needed in your project
2022 t elevator repair operation certificate examination question bank and simulation examination
Electronic components mall and data manual download website summary
C语言简易学生管理系统(含源码)
随机推荐
Yyds dry goods inventory TCP & UDP
2022广东省赛——编码信息获取 解析flag
Trie number dictionary tree
Flink1.13 SQL basic syntax (I) DDL, DML
【MATLAB】MATLAB 仿真模拟调制系统 — AM 已调信号的功率谱与相干解调
Flink1.13 basic SQL syntax (II) join operation
Error response from daemon: You cannot remove a running container 8d6f0d2850250627cd6c2acb2497002fc3
Zhongke panyun-d module analysis and scoring standard
[matlab] matlab simulation modulation system - DSB system
Flutter calls Gaode map app to realize location search, route planning and reverse geocoding
Flutter ‘/usr/lib/libswiftCore. dylib‘ (no such file)
【MATLAB】通信信号调制通用函数 — 傅里叶逆变换
拓扑排序和关键路径的图形化显示
The first introduction, stages and methods of defense system breakthrough from the perspective of the red team
[matlab] matlab simulates digital baseband transmission system - digital baseband transmission system
Zhongke Panyun - module a infrastructure setting and safety reinforcement scoring standard
空洞卷积、可变形卷积、可变形ROI Pooling
Zhongke Panyun - data analysis and forensics packet flag
[untitled]
Zhongke panyun-2022 Guangdong Trojan horse information acquisition and analysis