如何在图片上叠加半透明图片?

bonami 2002-08-30 10:49:26
我不知道该如何设定图片的alpha值,
目前只能写这么多代码,还望各位多多指教。
dim g as graphics = graphics.fromimage(obitmap)
g.DrawImage(System.Drawing.Image.FromFile(server.mappath("mark.gif")), New Point(100, 100))
...全文
418 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
OMyDoG 2002-12-14
  • 打赏
  • 举报
回复
vazi
vazi 2002-09-02
  • 打赏
  • 举报
回复
请适当修改文件路径,及水印的文字,希望有帮助啦

WaterMark.aspx
--------------------------------------------------------
<%@ Page language="c#" Codebehind="Watermark.aspx.cs" AutoEventWireup="false" Inherits="test.Watermark" %>


Watermark.aspx.cs
---------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace test
{
/// <summary>
/// Summary description for Watermark.
/// </summary>
public class Watermark : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
System.Drawing.Image originalimage = System.Drawing.Image.FromFile(@"D:\temp\" + Request.QueryString["src"]);
int imagewidth;
int imageheight;
int fontsize=300;
int x,y;
int a,re,gr,bl,x1,y1,z1;
int size;
Bitmap pattern;
SizeF sizeofstring;
bool foundfont;
imagewidth=originalimage.Width;
imageheight=originalimage.Height;
size=imagewidth*imageheight;
pattern = new Bitmap(imagewidth,imageheight);
Bitmap temp = new Bitmap(originalimage);
Graphics g = Graphics.FromImage(pattern);
Graphics tempg =Graphics.FromImage(originalimage);
//find a font size that will fit in the bitmap
foundfont=false;
g.Clear(Color.White);
while(foundfont==false)
{
Font fc = new Font("Georgia", fontsize, System.Drawing.FontStyle.Bold);

sizeofstring=new SizeF(imagewidth,imageheight);
sizeofstring=g.MeasureString("VAZI",fc);
if (sizeofstring.Width<pattern.Width)
{
if (sizeofstring.Height<pattern.Height)
{
foundfont=true;
g.DrawString("VAZI", fc, new SolidBrush(Color.Black),1,(pattern.Height-sizeofstring.Height)/2);

}

}
else
fontsize=fontsize-1;
}
//MessageBox.Show("Creating new graphic","GraphicsCopyright");
for(x=1;x<pattern.Width;x++)
{
for(y=1;y<pattern.Height;y++)//
{
if (pattern.GetPixel(x,y).ToArgb()==Color.Black.ToArgb())
{
a=temp.GetPixel(x,y).A;
re=temp.GetPixel(x,y).R;
gr=temp.GetPixel(x,y).G;
bl=temp.GetPixel(x,y).B;

x1=re;
y1=gr;
z1=bl;

if (bl+25<255)
bl=bl+25;

if (gr+25<255)
gr=gr+25;

if (re+25<255)
re=re+25;

if (x1-25>0)
x1=x1-25;

if (y1-25>0)
y1=y1-25;

if (z1-25>0)
z1=z1-25;



tempg.DrawEllipse(new Pen(new SolidBrush(Color.Black)),x,y+1,3,3);
tempg.DrawEllipse(new Pen(new SolidBrush(Color.FromArgb(a,x1,y1,z1))),x,y,1,1);
}
}
}
//MessageBox.Show("Output file is c:\\output.jpeg","GraphicsCopyright");
//tempg.Save();
Response.ContentType = "image/jpeg";
originalimage.Save(Response.OutputStream ,ImageFormat.Jpeg);
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
bonami 2002-09-02
  • 打赏
  • 举报
回复
等待回答中……
bonami 2002-09-01
  • 打赏
  • 举报
回复
up
龙腾九霄 2002-08-30
  • 打赏
  • 举报
回复
Style="FILTER:Alpha(opacity=50)"
龙腾九霄 2002-08-30
  • 打赏
  • 举报
回复
哦,看来要用到水印的功能了,我只知道怎么生成图片,做水印还不会呢,呵呵,失败失败。。。
bonami 2002-08-30
  • 打赏
  • 举报
回复
呵呵,是我没说清楚
我要的是两张图片在服务器叠加后,做为一张图片传到客户端,
为的是防止别人盗用图片吧

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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