十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
Dim bitmap1 As New Bitmap("D:\image\0183.jpg")‘panel1.backgroundimage
为企业提供成都网站建设、成都网站制作、网站优化、网络营销推广、竞价托管、品牌运营等营销获客服务。成都创新互联公司拥有网络营销运营团队,以丰富的互联网营销经验助力企业精准获客,真正落地解决中小企业营销获客难题,做到“让获客更简单”。自创立至今,成功用技术实力解决了企业“网站建设、网络品牌塑造、网络营销”三大难题,同时降低了营销成本,提高了有效客户转化率,获得了众多企业客户的高度认可!
Dim bitmap2 As New Bitmap(294, 294)’保存图,也就是绘制的大小。
Dim rect1 As New Rectangle(New Point, bitmap2.Size)‘昨天的问题,这里似乎写错了,当然也不算错,只是把新图(小图)扩展成原图大小(大图),这里改正为新图的原大小。
Dim rect2 As New Rectangle(New Point(6, 6), bitmap2.Size)
Dim g As Graphics = Graphics.FromImage(bitmap2)
e.Graphics.DrawImage(bitmap1, rect1, rect2, GraphicsUnit.Pixel)
g.DrawImage(bitmap1, rect1, rect2, GraphicsUnit.Pixel)
bitmap2.Save("d:\a.png", Drawing.Imaging.ImageFormat.Png)
第一步先用新的文件名来保存图像文件
第二步Dispose释放引用的图片文件
第三步删除旧的图片文件
第四步将新的图像文件 重命名为 旧的图片文件名
这样就可以达到你的目的了
将PictureBox控件里的图片,保存为文件:
1,文件格式不变化:
PictureBox1.Image.Save("C:\" Format(Now, "HH-mm-ss") ".bmp")
2,文件格式有变化:
PictureBox1.Image.Save("C:\" Format(Now, "HH-mm-ss") ".bmp", System.Drawing.Imaging.ImageFormat.Bmp)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If PictureBox1.Image Is Nothing Then Exit Sub
PictureBox1.Image.Save("xxx")
End Sub
提供两个思路
用printscreen,将其保存到文件,再调用outlook发出去,但是您说的超出一屏,就麻烦了;
以下代码保存为文件,引用自MSDN,由于我的SD版本不支持我的outlook,所以暂时无法给发送邮件的例子,请参考吧!
system.Windows.Forms.SendKeys.Send("%{PRTSC}")
If Not System.Windows.Forms.Clipboard.GetDataObject() Is Nothing Then
Dim oDataObj As IDataObject = System.Windows.Forms.Clipboard.GetDataObject()
If oDataObj.GetDataPresent(System.Windows.Forms.DataFormats.Bitmap) Then
Dim oImgObj As System.Drawing.Image = oDataObj.GetData(DataFormats.Bitmap, True)
'To Save as Bitmap
oImgObj.Save("F:\Test.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
'To Save as Jpeg
oImgObj.Save("D:\Test.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)
'To Save as Gif
oImgObj.Save("d:\Test.gif", System.Drawing.Imaging.ImageFormat.Gif)
End If
End If
2.另外出出报表,再调用outlook发出去,只给出数据性报表,而不一定是窗体本身;
VB6.0可使用SavePicture 语句来保存窗体或图像框中经修改的图片。
1)SavePicture 语句,从对象或控件(如果有一个与其相关)的 Picture 或 Image 属性中将图形保存到文件中。
说明:无论在设计时还是运行时图形从文件加载到对象的 Picture
属性,而且它是位图、图标、元文件或增强元文件,则图形将以原始文件同样的格式保存。如果它是 GIF 或 JPEG 文件,则将保存为位图文件。
2)AutoRedraw 属性,返回或设置从图形方法到持久图形的输出。
该属性为True,可使 Form 对象或 PictureBox
控件的自动重绘有效。图形和文本输出到屏幕,并存储在内存的图象中。该对象不接受绘制事件,必要时,用存储在内存中的图象进行重绘。
以下代码保存窗体装载并进行文字修饰的图片:
Option Explicit
Private Sub Command1_Click()
SavePicture Image, App.Path "\TEST" ' 将图片保存到文件。
End Sub
Private Sub Form_Click()
FontSize = 24
Print " 将图片保存到文件"
End Sub
Private Sub Form_Load()
Me.AutoRedraw = True
End Sub
3)若要保存为JPG图片需要采取使用API函数实现。参考以下步骤和代码:
a.在图片框加载需要添加文字水印的图片。
b.使用如下代码实现添加文字到图片框。
Private Sub CmdEdit_Click() '修改
Dim strTxt As String
strTxt = "风雨无阻 拍摄"
Picture1.FontSize = 18
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
c.将以下API转换图片格式代码放置于标准模块,模块命名为saveApg。
Option Explicit
Public Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Public Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type
Public Type EncoderParameter
GUID As GUID
NumberOfValues As Long
type As Long
Value As Long
End Type
Public Type EncoderParameters
Count As Long
Parameter As EncoderParameter
End Type
Public Declare Function GdiplusStartup Lib "GDIPlus" (token As Long, inputbuf As GdiplusStartupInput, ByVal outputbuf As Long) As Long
Public Declare Function GdiplusShutdown Lib "GDIPlus" (ByVal token As Long) As Long
Public Declare Function GdipCreateBitmapFromHBITMAP Lib "GDIPlus" (ByVal hbm As Long, ByVal hpal As Long, Bitmap As Long) As Long
Public Declare Function GdipDisposeImage Lib "GDIPlus" (ByVal Image As Long) As Long
Public Declare Function GdipSaveImageToFile Lib "GDIPlus" (ByVal Image As Long, ByVal fileName As Long, clsidEncoder As GUID, encoderParams As Any) As Long
Public Declare Function CLSIDFromString Lib "ole32" (ByVal str As Long, id As GUID) As Long
Public Declare Function GdipCreateBitmapFromFile Lib "GDIPlus" (ByVal fileName As Long, Bitmap As Long) As Long
Public Function PictureBoxSaveJPG(ByVal pict As StdPicture, ByVal fileName As String, Optional ByVal quality As Byte = 80) As Boolean
Dim tSI As GdiplusStartupInput
Dim lRes As Long
Dim lGDIP As Long
Dim lBitmap As Long
'初始化 GDI+
tSI.GdiplusVersion = 1
lRes = GdiplusStartup(lGDIP, tSI, 0)
If lRes = 0 Then
'从句柄创建 GDI+ 图像
lRes = GdipCreateBitmapFromHBITMAP(pict.Handle, 0, lBitmap)
If lRes = 0 Then
Dim tJpgEncoder As GUID
Dim tParams As EncoderParameters
'初始化解码器的GUID标识
CLSIDFromString StrPtr("{557CF401-1A04-11D3-9A73-0000F81EF32E}"), tJpgEncoder
'设置解码器参数
tParams.Count = 1
With tParams.Parameter ' Quality
'得到Quality参数的GUID标识
CLSIDFromString StrPtr("{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}"), .GUID
.NumberOfValues = 1
.type = 4
.Value = VarPtr(quality)
End With
'保存图像
lRes = GdipSaveImageToFile(lBitmap, StrPtr(fileName), tJpgEncoder, tParams)
'销毁GDI+图像
GdipDisposeImage lBitmap
End If
'销毁 GDI+
GdiplusShutdown lGDIP
End If
If lRes Then
PictureBoxSaveJPG = False
Else
PictureBoxSaveJPG = True
End If
End Function
d.使用以下代码实现将加好文字水印图片保存为jpg格式图片。
Private Sub Command3_Click() '保存为.jpg图片
' 设置“CancelError”为 True
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
' 设置标志
CommonDialog1.Flags = cdlOFNHideReadOnly
' 设置过滤器
CommonDialog1.Filter = "JPEG Files" "(*.jpg)|*.jpg"
' 指定缺省的过滤器
CommonDialog1.FilterIndex = 2
' 显示“打开”对话框
CommonDialog1.ShowSave
' 显示选定文件的名字
'MsgBox CommonDialog1.fileName
Set Picture2.Picture = Picture1.Image '转移Picture1所绘图为Picture2.Picture赋值
Dim ret As Boolean
ret = PictureBoxSaveJPG(Picture2, CommonDialog1.fileName) '保存压缩后的图片
If ret = False Then
MsgBox "保存失败"
End If
Exit Sub
ErrHandler:
' 用户按了“取消”按钮
Exit Sub
End Sub