我用asp.net写WEB的,打开一个透明背景的.gif文件(57px*69px),逐点判断,把其中的有色的换成绿色,
透明部分则不换,为什么显示不了呢?
替换部分:
for (int x = 0; x< imgBase.Width; x++)
{
for (int y = 0; y< imgBase.Height; y++)
{
Color pixel = imgBase.GetPixel(x,y);
if ( pixel.R > 0 && pixel.G > 0 && pixel.B >0 )
{
imgBase.SetPixel(x,y,Color.Green);
}
}
}
输出部分:
Response.ClearContent();
Response.ContentType = "image/gif"; 
Response.BinaryWrite(imgBase.Export());
                           Response.End();
请大家帮帮忙!如果我只是打开,然后输入没有问题,只是执行替换部分就不可以显示了

解决方案 »

  1.   

    怎么没人应.自己顶一顶!
    SORRY,最后一句话打错如果我只是读取,然后输出就没有问题,但如果执行替换部分图片就显示不出来了.各位大哥请帮忙.谢谢!
      

  2.   

    关注,我帮你顶
    你的imgBase是否是Bitmap?
      

  3.   

    public void SetPixel_Example(PaintEventArgs e)
    {
    // Create a Bitmap object from a file.
    Bitmap myBitmap = new Bitmap("Grapes.jpg");
    // Draw myBitmap to the screen.
    e.Graphics.DrawImage(
    myBitmap,
    0,
    0,
    myBitmap.Width,
    myBitmap.Height);
    // Set each pixel in myBitmap to black.
    for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++)
    {
    for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++)
    {
    myBitmap.SetPixel(Xcount, Ycount, Color.Black);
    }
    }
    // Draw myBitmap to the screen again.
    e.Graphics.DrawImage(
    myBitmap,
    myBitmap.Width,
    0,
    myBitmap.Width,
    myBitmap.Height);
    }
      

  4.   

    The123(在我地盤這 伱就得聽我的) ,你好.你是用WINFORM写的
    我在
    http://chs.gotdotnet.com/quickstart/winforms/doc/WinFormsGDIPlus.aspx
    上面也看过了,谢谢我想知道的是为什么我用WEBFORM写的替换颜色错在哪里了,为什么执行替换部分了的图就显示不了了呢.
      

  5.   

    http://www.giy.cn/Article_Show.asp?ArticleID=525
    这个教程也很好,可是还是不是我想要的,WEB 设计.
    大家帮帮忙
      

  6.   

    public void SetPixel_Example(PaintEventArgs e)
    {
    // Create a Bitmap object from a file.
    Bitmap myBitmap = new Bitmap("Grapes.jpg");
    // Draw myBitmap to the screen.
    e.Graphics.DrawImage(
    myBitmap,
    0,
    0,
    myBitmap.Width,
    myBitmap.Height);
    // Set each pixel in myBitmap to black.
    for (int Xcount = 0; Xcount < myBitmap.Width; Xcount++)
    {
    for (int Ycount = 0; Ycount < myBitmap.Height; Ycount++)
    {
    myBitmap.SetPixel(Xcount, Ycount, Color.Black);
    }
    }
    // Draw myBitmap to the screen again.
    e.Graphics.DrawImage(
    myBitmap,
    myBitmap.Width,
    0,
    myBitmap.Width,
    myBitmap.Height);
    }
      

  7.   

    我想知道的是为什么我用WEBFORM写的替换颜色错在哪里了,为什么执行替换部分了的图就显示不了了呢.
    ----------------
    画图都是一样的,你颜色改变了,你要重画一次
      

  8.   

    这几天都在上面搜,发现大家对于.GIF在WINFORM中的解释多一些.而在WEB中却没有很好的解决办法.原来SetPixel根本不支持256的.gif,所以靠GetPixel/SetPixel的方法根本行不通,而Graphics.DrawImage画出来也总不能形成透明.不知道大家有没有关注过这个问题.我在下面把我的代码帖出来.
      

  9.   

    Bitmap map = new Bitmap(imgBase.Width,imgBase.Height,PixelFormat.Format8bppIndexed); 

    ColorPalette cp = imgBase.Palette ; int CurrentEntry = cp.Entries.Length - 1; //get it's palette  ColorPalette ncp = map.Palette;  //copy all the entries from the old palette removing any transparency  int n = 0; 
    foreach(Color c in cp.Entries) 
    {
    ncp.Entries[n++] = c;
    }

    //Set the newly selected transparency  ncp.Entries[CurrentEntry] = Color.FromArgb(0,cp.Entries[CurrentEntry]);  //re-insert the palette  map.Palette = ncp;  BitmapData src = ((Bitmap)imgBase).LockBits(new Rectangle(0,0,imgBase.Width,imgBase.Height),ImageLockMode.ReadOnly,imgBase.PixelFormat);  BitmapData dst = map.LockBits(new Rectangle(0,0,map.Width,map.Height),ImageLockMode.WriteOnly,map.PixelFormat);  unsafe
    {  //steps through each pixel  for(int y = 0;y < imgBase.Height; y++) 
    { for(int x = 0;x < imgBase.Width; x++)  { 
    ((byte *)dst.Scan0.ToPointer())[(dst.Stride * y) + x] = ((byte *)src.Scan0.ToPointer())[(src.Stride * y) + x]; 

    }
    }
    //catch
    //{}
    //all done, unlock the bitmaps  ((Bitmap)imgBase).UnlockBits(src);  map.UnlockBits(dst); 这样的map再Response输出到WEB就没问题了.
      

  10.   

    我想问一下
    ((byte *)dst.Scan0.ToPointer())[(dst.Stride * y) + x] = ((byte *)src.Scan0.ToPointer())[(src.Stride * y) + x]; 
    这个过程中
    调色板的作用是什么
    map.Palette = ncp; 因为现在有第2幅图要加在第1幅图的上面,即2幅图合作一幅透明.gif,可我不知道怎么把第2幅图的Palette赋给map.烦请高手出马。谢谢