我不知道该如何设定图片的alpha值,
目前只能写这么多代码,还望各位多多指教。
dim g as graphics = graphics.fromimage(obitmap)
g.DrawImage(System.Drawing.Image.FromFile(server.mappath("mark.gif")), New Point(100, 100))
...全文
4187打赏收藏
如何在图片上叠加半透明图片?
我不知道该如何设定图片的alpha值, 目前只能写这么多代码,还望各位多多指教。 dim g as graphics = graphics.fromimage(obitmap) g.DrawImage(System.Drawing.Image.FromFile(server.mappath("mark.gif")), New Point(100, 100))
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;
#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);