惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Hacker News
The Hacker News
博客园_首页
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
V
Visual Studio Blog
小众软件
小众软件
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Full Disclosure
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Exploit Database - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
T
Threat Research - Cisco Blogs
AWS News Blog
AWS News Blog
T
Tor Project blog
Jina AI
Jina AI
GbyAI
GbyAI
C
Comments on: Blog
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
A
Arctic Wolf
有赞技术团队
有赞技术团队
SecWiki News
SecWiki News
L
Lohrmann on Cybersecurity
Security Latest
Security Latest
Webroot Blog
Webroot Blog
C
Cisco Blogs
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
K
Kaspersky official blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
宝玉的分享
宝玉的分享
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
H
Hacker News: Front Page
D
Darknet – Hacking Tools, Hacker News & Cyber Security
D
Docker
P
Palo Alto Networks Blog
The Register - Security
The Register - Security
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志

博客园 - flyingbird

.net DateTime 时间格式为毫秒 - flyingbird 今天的自省,从今天开始,做个勤快的人 一个总裁做企业的十条心得(转载) HttpWebRequest 向网站提交数据(转载) left join/right join/inner join(转载) 在C#.net中如何操作XML 关于Cookie中的Path和domain Javascript - HTML的request类 - flyingbird Access与Sql Server之ASP代码比较 - flyingbird - 博客园 WAP常见问题问答大全 HashTable的遍历 (转)web开发过程中要注意的问题 Javascript实现trim() 联动效果 http 500内部服务器错误解决 个人网站,个人站长,seo ,搜索引擎优化 快捷键 1个网页分成两个固定的部分来显示 生成静态页大全[ASP/PHP/ASPX] 收集自落伍论坛
水印+微图图(转http://tb.blog.csdn.net/TrackBack.aspx?PostId=721170)
flyingbird · 2007-11-02 · via 博客园 - flyingbird

Imports System.IO
Imports System.Drawing
Imports System.web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System
Public Class uploadimg
    ' filePath是客户文件的完全路径,savepath是保存在服务器的文件夹名,imgname是文件更名后的名字,包括后缀名,size是图片缩微的实际大小
    '这是缩微图形成
    Public Sub uploadSmallImg(ByVal filePath As String, ByVal savepath As String, ByVal ImgName As String, ByVal size As Int16)
        Dim Img As System.Drawing.Image = System.Drawing.Image.FromFile(filePath)
        Dim ImgOutput As Bitmap
        Dim neww, newh As Integer '考虑压缩失真问题,按比例保存
        If Img.Height <= Size And Img.Width <= Size Then '直接保存
            neww = Img.Height
            newh = Img.Width

        ElseIf Img.Width > Img.Height Then '按照width的比例保存
            neww = Size
            newh = Size * Img.Height / Img.Width
        Else '按照高度比例保存
            newh = Size
            neww = Size * Img.Width / Img.Height
        End If
        ImgOutput = New Bitmap(Img, neww, newh) '形成缩微图
        Img.Dispose()
        '图片上传到服务器文件
        Call savetofolder(ImgOutput, savepath + "s" + ImgName.ToLower)

    End Sub
    '保存原图,没有添加别的东西
    ' filePath是文件的完全路径,savepath是保存在服务器的文件夹名,imgname是文件更名后的名字,包括后缀名
    Public Sub uploadbigimg(ByVal filepath As String, ByVal savepath As String, ByVal imgname As String)

        Dim imgoutput As Bitmap = New Bitmap(filepath)
        '图片上传到服务器文件
        Call savetofolder(imgoutput, savepath + imgname.ToLower)
     
    End Sub
    ' 由时间形成的新的文件名称,包括了后缀名称,精确到毫秒的文件名称

    ' 因为jpg的图片最小,都考虑用jpg的格式

    Public Function newfilename() As String
        '精确到毫秒的文件名称,包括了后缀了, 以防上传文件同名
        Dim nowtime As DateTime = DateTime.Now
        Dim changefilename As String = nowtime.ToString("yyyyMMddHHmmss") + nowtime.Millisecond.ToString + ".jpg" '+ ImageExtensionName
        Return (changefilename.ToString)
      
    End Function
    '添加图片水印字符,然后上传
    ' filePath是客户文件的完全路径,savepath是保存在服务器的文件夹名,imgname是文件更名后的名字,包括后缀名,addstr是要填加的水印内容

    Public Sub addwatermark(ByVal filepath As String, ByVal savepath As String, ByVal imgname As String) ', ByVal addstr As String)
        '转换为位图
        Dim bmp As Bitmap = New Bitmap(filepath)
        Dim g As Graphics = Graphics.FromImage(bmp)
        Dim fontsize As Int16
        Dim addstr As String
        '考虑图的大小,定义水印字体的大小
        If bmp.Width < 120 Or bmp.Height < 120 Then
            fontsize = 10
            addstr = "--Cyt--" '图片太小添加--Cyt--
        Else : fontsize = 20
            addstr = "www.Caiyt.com" '图片比较大时添加www.Caiyt.com
        End If
        '定义画笔和字体
        Dim f As Font = New Font("Arial Black", fontsize, FontStyle.Italic)
        Dim b As Brush = New SolidBrush(Color.FromArgb(198, Color.Black)) '透明度100%
        '添加水印,取中间值添加
        g.DrawString(addstr, f, b, bmp.Width / 2, bmp.Height / 2)

        '保存添加了水印的图片,选择保存格式
        Call savetofolder(bmp, savepath + imgname.ToLower)
        g.Dispose()
    End Sub
    '添加水印图片,上传
    Public Sub addwatermarkimg(ByVal filepath As String, ByVal savepath As String, ByVal imgname As String, ByVal watermarkpath As String)
        Dim bmp As Bitmap = New Bitmap(filepath)
        Dim g As Graphics = Graphics.FromImage(bmp)

        '考虑图的大小,定义水印字体的大小
        If bmp.Width < 120 Or bmp.Height < 120 Then
            Dim fontsize As Int16
            Dim addstr As String
            fontsize = 10
            addstr = "--Cyt--" '图片太小添加--Cyt--,不添加图片
            Dim f As Font = New Font("Arial Black", fontsize, FontStyle.Italic)
            Dim b As Brush = New SolidBrush(Color.FromArgb(198, Color.Silver)) '透明度100%
            '添加水印,取中间值添加
            g.DrawString(addstr, f, b, bmp.Width / 2, bmp.Height / 2)
            '图片比较大时添加图片
        Else
            Dim markimg As Bitmap = New Bitmap(watermarkpath)
            'Rectangle(X,Y,width,height)
            '放在图片的左上角
            g.DrawImage(markimg, New Rectangle(10, 10, markimg.Width, markimg.Height), 0, 0, markimg.Width, markimg.Height, GraphicsUnit.Pixel)
        End If
        '定义画笔和字体

        '保存添加了水印的图片,选择保存格式
        Call savetofolder(bmp, savepath + imgname.ToLower)
        g.Dispose()
    End Sub
    Public Sub savetofolder(ByVal bmp As Bitmap, ByVal path As String)
        '按照给定的路径保存,统一按照jpg的格式保存

        '必须要求有上载的文件的格式,要不然不知道服务器是什么
        bmp.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg)
        bmp.Dispose()
    End Sub


End Class