{
string filepath = uploadFileValue;//上传的路径
string newName = DateTimeNowToString("yyyyMMddHHmmss");//新名字
string filehz = filepathSubstring(filepathLastIndexOf("") + 1)ToLowerInvariant();//后缀名
string uploadpath = ServerMapPath("/images/update/" + newName + "" + filehz);//服务器保存路径
if (!(uploadFilePostedFileContentLength > 0))
{
lblErrInfoText = "没有选择文件";
}
else
{
if (filehz == "jpg" || filehz == "gif" || filehz == "png")
{
if (FileExists(uploadpath))
{
lblErrInfoText = "已经有同名文件";
}
else
{
if (chboxIsInfoChecked == true)//加版权信息
{
if (txtLeftTextTrim() == "" || txtRightTextTrim() == "" || txtAddInfoTextTrim() == "")
{
ResponseWrite("<script>alert('请输入信息位置(半角数字)和信息文本!')</script>");
}
else
{
uploadFilePostedFileSaveAs(uploadpath);
lbtnDelImageVisible = true;
btnUpdateEnabled = false;
uploadFileVisible = false;
txtGameImageText = "images/update/" + newName + "" + filehz;
SystemThreadingThreadSleep(1000);
SystemDrawingImage img = SystemDrawingImageFromFile(uploadpath);
lblImgWidthText = imgWidthToString();
lblImgHeightText = imgHeightToString();
int width, height, left, right;
width = Int32Parse(lblImgWidthText);
height = Int32Parse(lblImgHeightText);
left = Int32Parse(txtLeftTextTrim());
right = Int32Parse(txtRightTextTrim());
SystemThreadingThreadSleep(1000);
//添加信息
string file = ServerMapPath("/" + txtGameImageText);
string newfile = "images/update/" + DateTimeNowToString("yyyyMMddHHmmss") + "jpg";
string strAddInfo = txtAddInfoText;
SystemDrawingImage oldimage = SystemDrawingImageFromFile(file);
ResponseClear();
Bitmap output = new Bitmap(oldimage);
Graphics gh = GraphicsFromImage(output);
string ColorHex = SelColorValue;
int r = Int16Parse(ColorHexSubstring(0, 2), SystemGlobalizationNumberStylesAllowHexSpecifier);
int g = Int16Parse(ColorHexSubstring(2, 2), SystemGlobalizationNumberStylesAllowHexSpecifier);
int b = Int16Parse(ColorHexSubstring(4, 2), SystemGlobalizationNumberStylesAllowHexSpecifier);
Color NewColor = ColorFromArgb(r, g, b);
ghDrawString(strAddInfo, new Font(ddlFontSelectedValue, intParse(ddlFontSizeSelectedValue)), new SolidBrush(NewColor), left, right);
outputSave(ServerMapPath(newfile), SystemDrawingImagingImageFormatJpeg);
ResponseContentType = "image/gif";
ImgPreviewImageUrl = newfile;
ImgPreviewVisible = true;
oldimageDispose();
txtGameImageText = newfile;
imgDispose();
FileDelete(file);
}
}
else//不加版权信息
{
uploadFilePostedFileSaveAs(uploadpath);
lbtnDelImageVisible = true;
btnUpdateEnabled = false;
uploadFileVisible = false;
txtGameImageText = "images/update/" + newName + "" + filehz;
SystemThreadingThreadSleep(1000);
SystemDrawingImage img = SystemDrawingImageFromFile(uploadpath);
lblImgWidthText = imgWidthToString();
lblImgHeightText = imgHeightToString();
ResponseContentType = "image/gif";
ImgPreviewImageUrl = txtGameImageText;
ImgPreviewVisible = true;
imgDispose();
}
SizeToSize();
}
}
else
{
ResponseWrite("<script>alert('只能上传jpg|gif|png格式的!')</script>");
}
}
}
catch
{
ResponseWrite("<script>alert('上传出错!')</script>");
}
以前写的上传代码
left, right分别代表版权信息的X,Y轴,这里是自己输入的,你可以通过对你输入的版权信息的字符像素长度和的宽,高计算得到。
ddlFontSelectedValue 字体选择
intParse(ddlFontSizeSelectedValue)) 字体大小
new SolidBrush(NewColor) 字体颜色最近有个工作任务就是给用户拍的照片打上水印并且上传到服务器
首先我们看看效果
话不多说 开搞
首先准备一张
准备好了接下来要轮到我们的Canvas来表演了
画布和准备好了那么我们开始吧文字绘制上去吧因为有些偏亮 那么白字就不容易辨识了 所以我们来给文字下面加个70%透明度的黑色底色吧
好了一切准备就绪开始绘制吧 先来个左上角的(此处给三倍margin是因为文字顶部的留白问题)
这里是dp和sp转PX的方法 很基础就不赘述了
因为涉及到的上传那么我们还需要将bitmap转成文件提交给服务器
最后是我封装的用来在各个位置加上文字水印有需要可以直接拿去使用
完结散花
什么是堡垒机的会话水印功能?
当用户在行云管家中通过RDP/VNC/SSH等协议访问云主机并获取其远程桌面/终端时,即创建了一个服务器远程桌面会话。一个完整的会话包含了协议类型、主机信息(IP、端口、用户口令等)、访问方式等一系列属性。行云管家堡垒机会话水印功能,是将访问该服务器的运维人员的账号等信息,以半透明水印的方式印在服务器远程桌面会话窗口上,当远程桌面会话窗口被录像、截屏、拍照,运维人员的信息也会被一并记录,方便事后回溯追责。
具体是这样的,我们现在在开发一个项目,其中有个功能是将用户填写的报表在线生成pdf下载,是通过流直接输出到用户的电脑里,服务器上不会存在生成的pdf文件,但是现在有一个问题,因为pdf文件页数是不确定的,所以在每一页加水印现在无法实现,请问怎样弄才能实现这一功能?我之前的思路是这样的,在生成pdf的java代码最后加个循环,通过得到document的页数然后用pdfContentByte在每一页加水印,但是我没找到可以定位到第几页的方法。部分代码:Java code responsesetContentType("text/html;charset=GBK");responsesetContentType("application/pdf");
responsesetHeader("Content-Disposition", "attachment;filename="
+ fileName + "pdf");
OutputStream outs = responsegetOutputStream(); // 获取输出流
PdfWriter writer = PdfWritergetInstance(doc, outs);
documentopen();
PdfContentByte under = writergetDirectContentUnder();
Java code//添加水印
underbeginText();
undersetColorFill(BaseColorLIGHT_GRAY);
undersetFontAndSize(bfTitle, 100);
undersetTextMatrix(70, 0);
int rise = 200;
for (int k = 0; k <waterMarkNamelength(); k++) {
undersetTextRise(rise);
char c = waterMarkNamecharAt(k);
undershowText(c + " ");
rise += 100;
}
underendText();
documentclose();//关闭
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)