C#两个picturebox 叠加后 要 显示透明怎么做

上面的是PICTUREBOX是相框下面是照片图片是PNG的请问怎么把相片透出来能上代码不... 上面的是PICTUREBOX 是相框 下面是照片 图片是PNG的 请问怎么把相片透 出来 能上代码不 展开
 我来答
匿名用户
2013-05-02
展开全部
在网上弄的一个加水印的方法,不知道你是否需要private void Form1_Load(object sender, EventArgs e)
{
Bitmap image=new Bitmap(pictureBox1.Image);
AddWaterMark(@"C:\Documents and Settings\Administrator\桌面\右上角.bmp", ref image);
pictureBox1.Image = image;
} /// <summary>
/// 加水印,对传入的Image对象操作
/// </summary>
/// <param name="watermarkFullPath">水印图片的完整路径</param>
/// <param name="imgPhoto">要加水印的Bitmap对象,直接在上面加水印(ref 引用传递)</param>
public static void AddWaterMark(string watermarkFullPath, ref Bitmap imgPhoto)
{
string Copyright = "Copyright ? 2005 - 2006 Lotour.com"; int phWidth = imgPhoto.Width;
int phHeight = imgPhoto.Height; //创建一个与原图尺寸相同的位图
Bitmap bmPhoto = new Bitmap(phWidth, phHeight, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution); //位图装载到一个Graphics对象
Graphics grPhoto = Graphics.FromImage(bmPhoto); //用水印BMP文件创建一个image对象
Image imgWatermark = new Bitmap(watermarkFullPath);
int wmWidth = imgWatermark.Width;
int wmHeight = imgWatermark.Height; //设置图片质量
grPhoto.SmoothingMode = SmoothingMode.AntiAlias; //以原始尺寸把照片图像画到此graphics对象
grPhoto.DrawImage(
imgPhoto, // Photo Image object
new Rectangle(0, 0, phWidth, phHeight), // Rectangle structure
0, // x-coordinate of the portion of the source image to draw.
0, // y-coordinate of the portion of the source image to draw.
phWidth, // Width of the portion of the source image to draw.
phHeight, // Height of the portion of the source image to draw.
GraphicsUnit.Pixel); // Units of measure //基于前面已修改的Bitmap创建一个新Bitmap
Bitmap bmWatermark = new Bitmap(bmPhoto);
bmWatermark.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
//Load this Bitmap into a new Graphic Object
Graphics grWatermark = Graphics.FromImage(bmWatermark); //To achieve a transulcent watermark we will apply (2) color
//manipulations by defineing a ImageAttributes object and
//seting (2) of its properties.
ImageAttributes imageAttributes = new ImageAttributes(); //第一步是以透明色(Alpha=0, R=0, G=0, B=0)来替换背景色
//为此我们将使用一个Colormap并用它来定义一个RemapTable
ColorMap colorMap = new ColorMap(); //水印被定义为一个100%的绿色背景l
//这将是我们以transparency来查找并替换的颜色
colorMap.OldColor = Color.FromArgb(255, 0, 255, 0);
colorMap.NewColor = Color.FromArgb(0, 0, 0, 0); ColorMap[] remapTable = { colorMap }; imageAttributes.SetRemapTable(remapTable, ColorAdjustType.Bitmap); //第二个颜色操作是用来改变水印的透明度
//用包涵the coordinates for the RGBA space的一个5x5 的矩阵
//设置第三行第三列to 0.3f we achive a level of opacity
float[][] colorMatrixElements = {
new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f},
new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 1.8f, 0.0f, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, 0.3f, 0.0f},
new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f}};
ColorMatrix wmColorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(wmColorMatrix, ColorMatrixFlag.Default,
ColorAdjustType.Bitmap); //水印放在图像的右上角
//向下10像素,向左10像素
// offset down 10 pixels and to the left 10 pixles
int xPosOfWm = ((phWidth - wmWidth) - 10);
int yPosOfWm = 10; //水印放在图像的右下角
xPosOfWm = phWidth - wmWidth;
yPosOfWm = phHeight - wmHeight; grWatermark.DrawImage(imgWatermark,
new Rectangle(xPosOfWm, yPosOfWm, wmWidth, wmHeight), //Set the detination Position
0, // 源图的横坐标位置
0, // 源图的纵坐标位置
wmWidth, // 水印宽度
wmHeight, // 水印高度
GraphicsUnit.Pixel, // Unit of measurment
imageAttributes); //ImageAttributes Object //以新图替换原始图
imgPhoto = bmWatermark;
grPhoto.Dispose();
grWatermark.Dispose();
imgWatermark.Dispose();
}
匿名用户
2013-05-02
展开全部
你把两个控件的透明度 调的 不一样 试试
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式