我现在要做的就是把一张手绘的线性图片(黑白的)给添加上颜色,线条也要求添加上颜色,请高手帮忙(最好能给 我一个例子)

解决方案 »

  1.   

    获得图形 然后判断颜色 是不是黑色 将黑色的点的RGB值 改成别的颜色
      

  2.   

    图片颜色替换吗?
    可以循环GetPixel获取像素颜色,这个方法有点慢。
    使用ColorMap和ImageAttributes替换旧的颜色
    ColorMap[] remapTable; //颜色转换列表
    g.DrawImage(
       img,
       destBounds,  // destination rectangle 
       0, 0,        // upper-left corner of source rectangle 
       bmp.Width,       // width of source rectangle
       bmp.Height,      // height of source rectangle
       GraphicsUnit.Pixel,
       imageAttributes);
      

  3.   

     
    g.DrawImage(
    img,
    destBounds, // destination rectangle  
    0, 0, // upper-left corner of source rectangle  
    bmp.Width, // width of source rectangle
    bmp.Height, // height of source rectangle
    GraphicsUnit.Pixel,
    imageAttributes);这个方法我试过,这个只能对对图片整体设置透明度,不是我想要的效果。我的想法是先给图片设置一个背景色,然后对不同的颜色设置不同的透明度,比如白色的设置透明度为完全不透明,黑色的就设置完全透明的,这样应该就能实现,可是这个透明度我咋改都不好使
      

  4.   


    /// <summary>
    /// 替换图片中的指定颜色为其它颜色
    /// </summary>
    class ImageMaker
    {
    ImageAttributes imageAttributes = new ImageAttributes();
    List<ColorMap> mapTable = new List<ColorMap>(); //颜色替换列表
    //添加颜色映射
    public void AddRemap(Color oldColor, Color newColor)
    {
    ColorMap colorMap = new ColorMap();
    colorMap.OldColor = oldColor;
    colorMap.NewColor = newColor;
    mapTable.Add(colorMap);
    } private Image img;
    public Image Img
    {
    get { return img; }
    set { img = value; }
    }        //根据颜色替换列表对img进行颜色替换
    public Bitmap Replace()
    {
    if (mapTable.Count < 1)
    {
    return new Bitmap(img);
    }
    imageAttributes.SetRemapTable(mapTable.ToArray(), ColorAdjustType.Bitmap);
    Bitmap bmp = new Bitmap(img.Width, img.Height);
    Rectangle destBounds = new Rectangle(Point.Empty, img.Size);
    using (Graphics g = Graphics.FromImage(bmp))
    {
    g.DrawImage(
       img,
       destBounds,  // destination rectangle 
       0, 0,        // upper-left corner of source rectangle 
       bmp.Width,       // width of source rectangle
       bmp.Height,      // height of source rectangle
       GraphicsUnit.Pixel,
       imageAttributes);
    }
    return bmp;
    } }
    private void button1_Click(object sender, EventArgs e)
    {
    ImageMaker imgMaker = new ImageMaker();
    imgMaker.Img = pictureBox1.Image;
         
    Color nc = Color.FromArgb(0, Color.Black);
    imgMaker.AddRemap(Color.Black, nc);//黑色透明 nc = Color.Blue;
    imgMaker.AddRemap(Color.White, nc); //白色变蓝色 Bitmap bitmap = imgMaker.Replace();
    pictureBox1.Image = bitmap;
     
    }可以实现多种颜色的替换,可能你的用法不对吧。