VB如何修改图片?~~~~~~~~~~~~~~~~~~~~~~~~

Snoworld 2008-10-29 02:35:59
如何把下面这张图片

修改为


修改内容如下:
在原图片下面增加一个宽度相同,高度为30像素的黑色长条,并加上"风雨无阻 拍摄"几个字,谢谢... ...
...全文
1379 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
zdingyun 2008-10-29
  • 打赏
  • 举报
回复
修改部分代码:
Private Sub CmdEdit_Click() '修改
Dim strTxt As String
strTxt = "风雨无阻 拍摄"
Picture1.FontSize = 18
Picture1.Height = Picture1.Height + 30
Picture1.Line (0, Picture1.ScaleHeight - 30)-(Picture1.ScaleWidth, Picture1.ScaleHeight), vbBlack, BF
Picture1.CurrentY = Picture1.ScaleHeight - 30
Picture1.CurrentX = Picture1.ScaleWidth / 2 - Picture1.TextWidth(strTxt) / 2
Picture1.ForeColor = vbWhite
Picture1.FontItalic = True
Picture1.Print strTxt
End Sub
zdingyun 2008-10-29
  • 打赏
  • 举报
回复
zdingyun 2008-10-29
  • 打赏
  • 举报
回复
zdingyun 2008-10-29
  • 打赏
  • 举报
回复
修改部分代码:

Private Sub Command1_Click() '修改
Dim strTxt As String
strTxt = "风雨无阻 拍摄"
Picture1.Line (0, Picture1.ScaleHeight - 30)-(Picture1.ScaleWidth, Picture1.ScaleHeight), vbBlack, BF
Picture1.CurrentY = Picture1.ScaleHeight - 30
Picture1.CurrentX = Picture1.ScaleWidth / 2 - Picture1.TextWidth(strTxt) ') / 2 - Picture1.TextWidth(strTxt)
Picture1.ForeColor = vbWhite
Picture1.FontSize = 18
Picture1.Print strTxt
End Sub
zdingyun 2008-10-29
  • 打赏
  • 举报
回复

Option Explicit
Private Const BI_RGB = 0&
Private Const DIB_RGB_COLORS = 0
Private Const BITMAPTYPE = &H4D42
Private Const INVALID_HANDLE_VALUE = (-1)
Private Const GENERIC_WRITE = &H40000000
Private Const CREATE_ALWAYS = 2
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Type BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type RGBQUAD
rgbBlue As Byte
rgbGreen As Byte
rgbRed As Byte
rgbReserved As Byte
End Type
Private Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As RGBQUAD
End Type
Private Type BITMAPFILEHEADER
bfType As Integer
bfSize As Long
bfReserved1 As Integer
bfReserved2 As Integer
bfOffBits As Long
End Type
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateDIBSection Lib "gdi32" (ByVal hdc As Long, pBitmapInfo As BITMAPINFO, ByVal un As Long, lplpVoid As Long, ByVal handle As Long, ByVal dw As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Sub CmdOpen_Click()
'打开文件并显示在Picture1中
On Error GoTo Err_handle
CmnDlg1.DialogTitle = "打开"
CmnDlg1.ShowOpen
Picture1.Picture = LoadPicture(CmnDlg1.FileName)
Picture1.Height = Picture1.Height + 30
Exit Sub
Err_handle:
Exit Sub
End Sub

Private Sub CmdSave_Click()
'保存转换后的图像
Dim hmemDC As Long
Dim hmemBMP As Long
Dim lpmemBits As Long
Dim bmp_info As BITMAPINFO
Dim hFile As Long
Dim bmpfile_info As BITMAPFILEHEADER
Dim lpBytesWritten As Long
Picture1.ScaleMode = vbPixels
With bmp_info.bmiHeader
.biSize = LenB(bmp_info.bmiHeader)
.biWidth = Picture1.ScaleWidth
.biHeight = Picture1.ScaleHeight
.biPlanes = 1
.biBitCount = 24
.biCompression = BI_RGB
.biSizeImage = .biHeight * (((.biWidth * .biBitCount + 31) And &HFFFFFFE0) \ 8)
End With
hmemDC = CreateCompatibleDC(Picture1.hdc)
hmemBMP = CreateDIBSection(Picture1.hdc, bmp_info, DIB_RGB_COLORS, lpmemBits, 0, 0)
SelectObject hmemDC, hmemBMP
BitBlt hmemDC, 0, 0, bmp_info.bmiHeader.biWidth, bmp_info.bmiHeader.biHeight, Picture1.hdc, 0, 0, vbSrcCopy
'保存图片
hFile = CreateFile(App.Path & "\test.bmp", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
If hFile <> INVALID_HANDLE_VALUE Then
With bmpfile_info
.bfType = BITMAPTYPE
.bfOffBits = 14 + bmp_info.bmiHeader.biSize
.bfSize = .bfOffBits + bmp_info.bmiHeader.biSizeImage
End With
WriteFile hFile, bmpfile_info.bfType, 2, lpBytesWritten, 0
WriteFile hFile, bmpfile_info.bfSize, 12, lpBytesWritten, 0
WriteFile hFile, bmp_info.bmiHeader, bmp_info.bmiHeader.biSize, lpBytesWritten, 0
WriteFile hFile, ByVal lpmemBits, bmp_info.bmiHeader.biSizeImage, lpBytesWritten, 0
CloseHandle hFile
End If
DeleteObject hmemBMP
DeleteDC hmemDC
End Sub

Private Sub Command1_Click() '修改
Dim strTxt As String
strTxt = "风雨无阻 拍摄"
Picture1.Line (0, Picture1.Height - 34)-(Picture1.Width, Picture1.Height), vbBlack, BF
Picture1.CurrentY = Picture1.Height - 32
Picture1.CurrentX = Picture1.ScaleWidth / 2 - Picture1.TextWidth(strTxt) ') / 2 - Picture1.TextWidth(strTxt)
Picture1.ForeColor = vbWhite
Picture1.FontSize = 18
Picture1.Print strTxt
End Sub


Private Sub Form_Load()
Picture1.AutoSize = True
Picture1.AutoRedraw = True
End Sub
laviewpbt 2008-10-29
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim str As String
str = "风雨无阻 拍摄"
With Picture1
.AutoSize = True
.ScaleMode = 3
.AutoRedraw = True
.Picture = LoadPicture("c:\1.bmp")
Picture1.Line (0, .ScaleHeight - 30)-(.ScaleWidth, .ScaleHeight), vbBlack, BF
.CurrentX = (.ScaleWidth - .TextWidth(str)) / 2
.CurrentY = .ScaleHeight - 30 + (30 - .TextHeight(str)) / 2
.ForeColor = vbWhite
Picture1.Print str
End With

SavePicture Picture1.Image, "c:\2.bmp"
End Sub

要改变 字体的话可以 直接更改Picture1的font属性
Snoworld 2008-10-29
  • 打赏
  • 举报
回复
谢谢大家,问题已经解决.
特别感谢zdingyun ,
发现CSDN的好人越来越多了...
zdingyun 2008-10-29
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 chenjl1031 的回复:]
引用 11 楼 hank212 的回复:
能不能把他保存成JPG格式的图片...


图片保为JPG文件,可以用GDI+。
看看这里(VB源码):
http://www.cnblogs.com/wangminbai/archive/2008/03/23/1118638.html
[/Quote]
感谢13 楼 chenjl1031提供链接
东方之珠 2008-10-29
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 hank212 的回复:]
能不能把他保存成JPG格式的图片...
[/Quote]

图片保为JPG文件,可以用GDI+。
看看这里(VB源码):
http://www.cnblogs.com/wangminbai/archive/2008/03/23/1118638.html
zdingyun 2008-10-29
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 hank212 的回复:]
能不能把他保存成JPG格式的图片...
[/Quote]
LZ:目前未找到VB用代码解决的方法。只能用WINDOWS的画图板打开*.Bmp图片另存为
*.JPG图片
Snoworld 2008-10-29
  • 打赏
  • 举报
回复
能不能把他保存成JPG格式的图片...
zdingyun 2008-10-29
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 hank212 的回复:]
已经达到想要的效果,
但是编辑之后的图片很大,以前的只有100多K,现在达到了1.95M,
如何压缩成以前的大小...
[/Quote]
LZ:给出的代码是保存为*.bmp位图的代码。
Snoworld 2008-10-29
  • 打赏
  • 举报
回复
已经达到想要的效果,
但是编辑之后的图片很大,以前的只有100多K,现在达到了1.95M,
如何压缩成以前的大小...
vb.net操作DataGridView控件的用法的集合,包括: 1. DataGridView当前的单元格属性取得、变更 2. DataGridView编辑属性 3. DataGridView最下面一列新追加行非表示 4. DataGridView判断当前选中行是否为新追加的行 5. DataGridView删除行可否设定 6. DataGridView行列不表示和删除 DataGridView控件用法合集(二) 7. DataGridView行列宽度高度设置为不能编辑 8. DataGridView行高列幅自动调整 9. DataGridView指定行列冻结 10. DataGridView列顺序变更可否设定 11. DataGridView行复数选择 12. DataGridView选择的行、列、单元格取得 DataGridView控件用法合集(三) 13. DataGridView指定单元格是否表示 14. DataGridView表头部单元格取得 15. DataGridView表头部单元格文字列设定 16. DataGridView选择的部分拷贝至剪贴板 17.DataGridView粘贴 18. DataGridView单元格上ToolTip表示设定(鼠标移动到相应单元格上时,弹出说明信息) DataGridView控件用法合集(四) 19. DataGridView中的ContextMenuStrip属性 20. DataGridView指定滚动框位置 21. DataGridView手动追加列 22. DataGridView全体分界线样式设置 23. DataGridView根据单元格属性更改显示内容 24. DataGridView新追加行的行高样式设置る 25. DataGridView新追加行单元格默认值设置 DataGridView中输入错误数据的处理(五) 26. DataGridView单元格数据错误标签表示 27. DataGridView单元格内输入值正确性判断 28. DataGridView单元格输入错误值事件的捕获 DataGridView控件用法合集(六) 29. DataGridView行排序(点击列表头自动排序的设置) 30. DataGridView自动行排序(新追加值也会自动排序) 31. DataGridView自动行排序禁止情况下的排序 32. DataGridView指定列指定排序 DataGridView控件用法合集(七) 33. DataGridView单元格样式设置 34. DataGridView文字表示位置的设定 35. DataGridView单元格内文字列换行 36. DataGridView单元格DBNull值表示的设定 37. DataGridView单元格样式格式化 38. DataGridView指定单元格颜色设定 39. DataGridView单元格文字字体设置 40. DataGridView根据单元格值设定单元格样式 DataGridView控件用法合集(八) 41. DataGridView设置单元格背景颜色 42. DataGridView行样式描画 43. DataGridView显示行号 44. DataGridView焦点所在单元格焦点框不显示的设定 DataGridView控件用法合集(九) 45. DataGridView中显示选择框CheckBox 46. DataGridView中显示下拉框ComboBox 47. DataGridView单击打开下拉框 48. DataGridView中显示按钮 49. DataGridView中显示链接 50. DataGridView中显示图像 DataGridView控件用法合集(十) 51. DataGridView编辑中单元格控件取得 52. DataGridView输入自动完成 53. DataGridView单元格编辑时键盘KEY事件取得 54. DataGridView下拉框(ComboBox)单元格编辑时事件取得 55. DataGridView下拉框(ComboBox)单元格允许文字输入设定 DataGridView控件用法合集(十一) 56. DataGridView根据值不同在另一列中显示相应图片 57. DataGridView中显示进度条(ProgressBar) 58. DataGridView中添加MaskedTextBox DataGridView控件用法合集(十二) 59. DataGridView中Enter键按下焦点移至旁边的单元格 60. DataGridView行集合化(Group)

809

社区成员

发帖
与我相关
我的任务
社区描述
VB 多媒体
社区管理员
  • 多媒体
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧