Imports System.IO
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D
Public Class Form1
Private sourceImage As Bitmap
Private isDrawing As Boolean
Private lastPoint As Point
Private sourceImage1 As Bitmap
Private sourceImage2 As Bitmap
Private isDrawingText As Boolean
Private lastTextPoint As Point
'加一个集合来存储每次输入文字的位置和文本
Private textPositionsAndTexts As New List(Of Tuple(Of Point, String))
Private isSelecting As Boolean
Private selectionStartPoint As Point
Private selectionEndPoint As Point
Private isMovingText As Boolean '标识是否正在移动文字
Private movingTextIndex As Integer '正在移动的文字在集合中的索引
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
InitializeTrackBar()
End Sub
Private Sub InitializeTrackBar()
'置滑动条的属性
TrackBar1.Minimum = -255
TrackBar1.Maximum = 255
TrackBar1.Value = 0
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button1.Click
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.Filter = "图片文件|*.jpg;*.jpeg;*.png;*.gif;*.bmp"
openFileDialog1.Title = "选择图片"
If openFileDialog1.ShowDialog() = DialogResult.OK Then
sourceImage = New Bitmap(openFileDialog1.FileName)
PictureBox1.Image = sourceImage
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button2.Click
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "JPEG 图像|*.jpg"
saveFileDialog1.Title = "保存图片"
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
Try
Dim bitmap As New Bitmap(sourceImage)
bitmap.Save(saveFileDialog1.FileName, ImageFormat.Jpeg)
Catch ex As Exception
MessageBox.Show("保存图片时出错: " & ex.Message)
End Try
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button3.Click
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "JPEG 图像|*.jpg|PNG 图像|*.png|BMP 图像|*.bmp"
saveFileDialog1.Title = "保存图片"
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
Try
Dim bitmap As New Bitmap(sourceImage)
Select Case saveFileDialog1.FilterIndex
Case 1 'JPEG
bitmap.Save(saveFileDialog1.FileName, ImageFormat.Jpeg)
Case 2 'PNG
bitmap.Save(saveFileDialog1.FileName, ImageFormat.Png)
Case 3 'BMP
bitmap.Save(saveFileDialog1.FileName, ImageFormat.Bmp)
End Select
Catch ex As Exception
MessageBox.Show("保存图片时出错: " & ex.Message)
End Try
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button4.Click
If sourceImage IsNot Nothing Then
Dim startX As Integer = 10 '裁剪起始的 X 坐标
Dim startY As Integer = 10 '裁剪起始的 Y 坐标
Dim cropWidth As Integer = 100 '裁剪的宽度
Dim cropHeight As Integer = 100 '裁剪的高度
Dim croppedImage As Bitmap = New Bitmap(cropWidth, cropHeight)
Using graphics As Graphics = Graphics.FromImage(croppedImage)
graphics.DrawImage(sourceImage, New Rectangle(0, 0, cropWidth, cropHeight), startX, startY, cropWidth, cropHeight, GraphicsUnit.Pixel)
End Using
Dim saveFileDialog1 As New SaveFileDialog()
saveFileDialog1.Filter = "JPEG 图像|*.jpg|PNG 图像|*.png|BMP 图像|*.bmp"
saveFileDialog1.Title = "保存裁剪后的图片"
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
Try
Select Case saveFileDialog1.FilterIndex
Case 1 'JPEG
croppedImage.Save(saveFileDialog1.FileName, ImageFormat.Jpeg)
Case 2 'PNG
croppedImage.Save(saveFileDialog1.FileName, ImageFormat.Png)
Case 3 'BMP
croppedImage.Save(saveFileDialog1.FileName, ImageFormat.Bmp)
End Select
Catch ex As Exception
MessageBox.Show("保存图片时出错: " & ex.Message)
End Try
End If
Else
MessageBox.Show("请先打开图片再进行裁剪操作")
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button5.Click
If sourceImage IsNot Nothing Then
Dim flippedHorizontallyImage As Bitmap = FlipImageHorizontally(sourceImage)
PictureBox1.Image = flippedHorizontallyImage
Else
MessageBox.Show("请先打开图片再进行水平翻转操作")
End If
End Sub
Private Function FlipImageHorizontally(ByVal image As Bitmap) As Bitmap
Dim flippedImage As New Bitmap(image.Width, image.Height)
For y As Integer = 0 To image.Height - 1
For x As Integer = 0 To image.Width - 1
flippedImage.SetPixel(image.Width - 1 - x, y, image.GetPixel(x, y))
Next
Next
Return flippedImage
End Function
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button6.Click
If sourceImage IsNot Nothing Then
Dim flippedVerticallyImage As Bitmap = FlipImageVertically(sourceImage)
PictureBox1.Image = flippedVerticallyImage
Else
MessageBox.Show("请先打开图片再进行垂直翻转操作")
End If
End Sub
Private Function FlipImageVertically(ByVal image As Bitmap) As Bitmap
Dim flippedImage As New Bitmap(image.Width, image.Height)
For y As Integer = 0 To image.Height - 1
For x As Integer = 0 To image.Width - 1
flippedImage.SetPixel(x, image.Height - 1 - y, image.GetPixel(x, y))
Next
Next
Return flippedImage
End Function
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Button7.Click
If sourceImage IsNot Nothing Then
Using graphics As Graphics = Graphics.FromImage(sourceImage)
Dim font As New Font("Arial", 20, FontStyle.Bold)
Dim brush As New SolidBrush(Color.Red)
graphics.SmoothingMode = SmoothingMode.AntiAlias
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic
graphics.DrawString("这是按钮输入的文字", font, brush, 50, 50)
End Using
PictureBox1.Image = sourceImage
Else
MessageBox.Show("请先打开图片再添加文字")
End If
End Sub
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)Handles PictureBox1.MouseDown
If e.Button = MouseButtons.Left Then
isSelecting = True
selectionStartPoint = e.Location
End If
If e.Button = MouseButtons.Right Then
If isDrawingText Then
'开始输入文字时,记录初始位�
没有合适的资源?快使用搜索试试~ 我知道了~
VS2010旗舰版VB.NET版本图片编辑源代码QZQ.zip
共40个文件
vb:6个
txt:5个
jpg:5个
需积分: 5 0 下载量 150 浏览量
2024-08-11
08:59:07
上传
评论
收藏 1.24MB ZIP 举报
温馨提示
VS2010旗舰版VB.NET版本图片编辑源代码QZQ.zip
资源推荐
资源详情
资源评论
收起资源包目录
VS2010旗舰版VB.NET版本图片编辑源代码QZQ.zip (40个子文件)
VS2010旗舰版VB.NET版本图片编辑源代码QZQ
ZQ代码.txt 20KB
WindowsApplication1
WindowsApplication1.vbproj.user 143B
Form1.Designer.vb 15KB
My Project
Settings.Designer.vb 3KB
Application.myapp 510B
Resources.Designer.vb 3KB
AssemblyInfo.vb 1KB
Application.Designer.vb 1KB
Settings.settings 279B
Resources.resx 5KB
obj
x86
Release
Debug
WindowsApplication1.vbproj.GenerateResource.Cache 975B
WindowsApplication1.Resources.resources 180B
WindowsApplication1.vbproj.FileListAbsolute.txt 15KB
DesignTimeResolveAssemblyReferencesInput.cache 6KB
WindowsApplication1.pdb 72KB
TempPE
My Project.Resources.Designer.vb.dll 8KB
WindowsApplication1.exe 797KB
WindowsApplication1.xml 708B
WindowsApplication1.Form1.resources 180B
DesignTimeResolveAssemblyReferences.cache 3KB
WindowsApplication1.vbproj 5KB
Form1.vb 25KB
bin
Release
Debug
WindowsApplication1.vshost.exe.manifest 490B
WindowsApplication1.pdb 72KB
WindowsApplication1.vshost.exe 11KB
WindowsApplication1.exe 797KB
WindowsApplication1.xml 708B
Form1.resx 6KB
aa.jpg 21KB
1.jpg 13KB
WindowsApplication1.suo 28KB
WindowsApplication1代码.txt 25KB
1.png 140KB
正确代码.txt 17KB
06c976063cd0fa037ee27baacbb99050.jpg 18KB
1.bmp 187KB
WindowsApplication1.sln 899B
zz.jpg 16KB
26110cec4839cc453041055584b193b0.jpg 14KB
程序代码.txt 25KB
共 40 条
- 1
资源评论
EasySoft易软
- 粉丝: 3951
- 资源: 1358
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功