| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2554 人关注过本帖
标题:求教如何 透明GIF图片如何在C#实现与背景从和
只看楼主 加入收藏
rantilin
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-3-28
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:6 
求教如何 透明GIF图片如何在C#实现与背景从和
采蘑菇.rar (117.99 KB)

当我加背景图片的时候出现 白色框框
求教高人指点
搜索更多相关主题的帖子: GIF 
2010-04-06 10:50
qubo1982
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:1
帖 子:367
专家分:1132
注 册:2009-3-18
收藏
得分:0 
把图片多余的部份做成透明的吧,没必要在程序中去处理啊
2010-04-06 10:58
rantilin
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-3-28
收藏
得分:0 
回复 2楼 qubo1982
我在PS里把多余的背景都去掉了的  是透明的 保存的GIF
2010-04-06 11:01
rantilin
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-3-28
收藏
得分:0 
回复 2楼 qubo1982
就是不知道如何实现  GIF图片和背景图片 从和
2010-04-06 11:03
qubo1982
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:1
帖 子:367
专家分:1132
注 册:2009-3-18
收藏
得分:0 
在DrawImage方法中有一个重载中要用到一个ImageAttributes对象,
在ImageAttributes对象有一个方法ClearColorKey(),你可以试一下,看能解决你的问题不
2010-04-06 11:28
封闭
Rank: 9Rank: 9Rank: 9
来 自:广东省汕头市
等 级:蜘蛛侠
威 望:1
帖 子:501
专家分:1084
注 册:2007-9-14
收藏
得分:0 
LZ的意思就是说,要把白色的背景给去掉,简单点说就是修饰窗体是不是?
2010-04-06 19:01
封闭
Rank: 9Rank: 9Rank: 9
来 自:广东省汕头市
等 级:蜘蛛侠
威 望:1
帖 子:501
专家分:1084
注 册:2007-9-14
收藏
得分:20 
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace TestBackGround
{
    class ShowFrom
    {
        public ShowFrom()
        { }

        //创建支持位图区域的控件
        public static void CreateControlRegion(Control control, Bitmap bitmap)
        {

            //设置控件大小为位图大小
            control.Width = bitmap.Width;           //设置窗体的宽度
            control.Height = bitmap.Height;         //设置窗体的高度

            //当控件为form时
            if (control is System.Windows.Forms.Form)
            {
                //强制转换为form
                Form form = (Form)control;
                //当Form的边界FormBorderStyle不为None时,应将Form的大小设置成比位图大小稍大一点
                form.Width = control.Width;
                form.Height = control.Height;
                //将Form的边界FormBorderStyle设置为不应用任何样式
                form.FormBorderStyle = FormBorderStyle.None;
                //将位图设为窗体背景
                form.BackgroundImage = bitmap;
                //计算位图中不隐藏部分的边界
                GraphicsPath graphicsPath = CalculateControlGraphicsPath(bitmap);
                //应用到新的区域
                form.Region = new Region(graphicsPath);
            }
               
            
        }

        private static GraphicsPath CalculateControlGraphicsPath(Bitmap bitmap)
        {
            //创建GraphicsPath对象
            GraphicsPath graphicsPath = new GraphicsPath();

            //得到左上角颜色
            Color colorTransparent = bitmap.GetPixel(0 , 0);

            //找到第一个坐标x
            int colOpaquePixel = 0;

            //偏历所有行(Y方向)
            for (int row = 0; row < bitmap.Height; row++)
            {
                //重新指定colOpaquePixel的值
                colOpaquePixel = 0;
                //偏历所有列(X方向)
                for (int col = 0; col < bitmap.Width; col++)
                {
                    //如果是不需要透明处理的点则标记,然后继续偏历
                    if (bitmap.GetPixel(col, row) != colorTransparent)
                    {
                        //记录当前位置
                        colOpaquePixel = col;
                        //建立新变量来记录当前点
                        int colNext = col;
                        //从找到不透明的点开始,到透明点开始或到达图片宽度
                        for (colNext = colOpaquePixel; colNext < bitmap.Width; colNext++)
                            if (bitmap.GetPixel(colNext, row) == colorTransparent)
                                break;
                        //将不透明点加到GraphicsPath的AddRectangle()方法里
                        graphicsPath.AddRectangle(new Rectangle(colOpaquePixel , row , colNext - colOpaquePixel , 1));
                        col = colNext;
                    }
                }
            }
            return graphicsPath;
        }
    }
}


在窗体加载时,让它去调用;
ShowFrom ShowFrom= new ShowFrom();
ShowFrom.CreateControlRegion(this, new Bitmap(@"图片地址"));
2010-04-06 19:03
快速回复:求教如何 透明GIF图片如何在C#实现与背景从和
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012427 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved