当前位置:网站首页>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
效果很好,可以去除一些褶皱,多余的背景
边栏推荐
- RSA加密应用常见缺陷的原理与实践
- Thread pool: use thread pool to optimize query speed
- [paper summary] zero shot semantic segmentation
- A summary of the 8544 problem that SolidWorks Standard cannot obtain a license
- 数据标注是一块肥肉,盯上这块肉的不止中国丨曼孚科技
- 加密和解密
- ETCD数据库源码分析——初始化总览
- 2022危险化学品经营单位安全管理人员上岗证题库及答案
- 空洞卷积、可变形卷积、可变形ROI Pooling
- C语言简易学生管理系统(含源码)
猜你喜欢
补某视频网站的js,进行视频解密
Headache delayed double deletion
Zhongke panyun-2022 Guangdong Trojan horse information acquisition and analysis
LM small programmable controller software (based on CoDeSys) note 22: error 4268/4052
appliedzkp zkevm(13)中的Public Inputs
Notes on the paper "cross view transformers for real time map view semantic segmentation"
2022 question bank and answers for safety management personnel of hazardous chemical business units
Character types of C language
LM小型可编程控制器软件(基于CoDeSys)笔记二十二:错误4268/4052
[paper summary] zero shot semantic segmentation
随机推荐
【MATLAB】MATLAB 仿真数字带通传输系统 — QPSK 和 OQPSK 系统
TCP状态转换图
如何使用postman实现简单的接口关联【增删改查】
cmake
Trie number dictionary tree
【QT】定时器
Zhongke Panyun - module a infrastructure setting and safety reinforcement scoring standard
[paper summary] zero shot semantic segmentation
【MATLAB】MATLAB 仿真模拟调制系统 — AM 已调信号的功率谱与相干解调
Topological sorting and graphical display of critical path
[matlab] matlab simulation of modulation system - power spectrum and coherent demodulation of AM modulated signal
Exercise bubble sort
Nodejs learning document
Electronic components mall and data manual download website summary
VSCode的有用插件
[matlab] general function of communication signal modulation - generation of narrow-band Gaussian white noise
Get the ID of the record just inserted from laravel
Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
Graduation design of small programs -- small programs of food and recipes
When using flash to store parameters, the code area of flash is erased, which leads to the interrupt of entering hardware error