我用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();
请大家帮帮忙!如果我只是打开,然后输入没有问题,只是执行替换部分就不可以显示了
透明部分则不换,为什么显示不了呢?
替换部分:
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();
请大家帮帮忙!如果我只是打开,然后输入没有问题,只是执行替换部分就不可以显示了
解决方案 »
- web 应用程序打包
- .net4.0 dynamic问题,属性名在一个变量中,该怎么操作呢??
- 求教一个SQL语句。在线等啊
- 谁有 jquery Flexigrid+net的案例 不需要wvc
- 如果用SQL语句将2006-08-18 14:47:50显示结果为2006-08-18,在线等
- 各位,我这里有一个问题需要您帮我解决一下,本人在此不胜感激,谢谢了!
- 程序员就这样没有前途吗?
- 下面的编码是什么编码,怎么解
- 如何实现诸如http://www.csdn.net/expert/PostNew?room=33这样的链接
- 有必要用dispose()这个方法吗?
- 关于获得toolbar里的ToolbarDropDownList值的问题
- EnableViewState 属性禁用控件的视图状态有什么作用啊
SORRY,最后一句话打错如果我只是读取,然后输出就没有问题,但如果执行替换部分图片就显示不出来了.各位大哥请帮忙.谢谢!
你的imgBase是否是Bitmap?
{
// 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);
}
我在
http://chs.gotdotnet.com/quickstart/winforms/doc/WinFormsGDIPlus.aspx
上面也看过了,谢谢我想知道的是为什么我用WEBFORM写的替换颜色错在哪里了,为什么执行替换部分了的图就显示不了了呢.
这个教程也很好,可是还是不是我想要的,WEB 设计.
大家帮帮忙
{
// 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);
}
----------------
画图都是一样的,你颜色改变了,你要重画一次
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就没问题了.
((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.烦请高手出马。谢谢