Slivrtlight客户端显示图片的时候,如何对图片颜色进行过滤然后显示出来!

roberqwe 2012-02-10 01:09:20

之前在js里面,图片过滤可以这样处理:

var tmpHTML = "<IMG id='mapserverimgid' style='Z-INDEX: 1; cursor: hand;Filter: Chroma(color=#FFFFFF); LEFT: 0px; WIDTH: "+document.body.clientWidth+"px; POSITION: absolute; TOP: 0px; HEIGHT: "+document.body.clientHeight+"px' src='"+tmpresponse+"'>";

现在在 Slivrtlight客户端显示图片的时候,如何对图片颜色进行过滤呢?
...全文
127 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zz05962860978 2012-02-11
  • 打赏
  • 举报
回复
没时间写代码调试,大概这样的方向试试看:
WriteableBitmap bitmap = this.DrawToBitmap();
for (int y = 0; y < bitmap.PixelHeight; y++)
{
for (int x = 0; x < bitmap.PixelWidth; x++)
{ //取得每一個pixel
int pixelLocation = bitmap.PixelWidth * y + x;
int pixel = bitmap.Pixels[pixelLocation];
//这里byte[4]填写为需要判断的指定RGB颜色
if(BitConverter.ToInt32(new byte[4] { 0, 0, 0, 0 }, 0) == pixel)
bitmap.Pixels[pixelLocation] = BitConverter.ToInt32(new byte[4] { 0, 0, 0, 0 }, 0); //这里byte[4]为要替换的RGB颜色
}
}
this.m_image.Source = bitmap;
roberqwe 2012-02-10
  • 打赏
  • 举报
回复
没看明白,能写出来吗
zz05962860978 2012-02-10
  • 打赏
  • 举报
回复
例如图片转黑白的例子里,把/3的黑白化处理改为,if判断如果是黑色,就转化为透明BitConverter.ToInt32(new byte[4] { 0, 0, 0, 0 }, 0)或你需要的颜色就可以了啊
roberqwe 2012-02-10
  • 打赏
  • 举报
回复
有人搞过吗,帮一下忙撒
roberqwe 2012-02-10
  • 打赏
  • 举报
回复
这里有一段,貌似是转黑白色的
WriteableBitmap bitmap = this.DrawToBitmap();
for (int y = 0; y < bitmap.PixelHeight; y++)
{
for (int x = 0; x < bitmap.PixelWidth; x++)
{ //取得每一個pixel
int pixelLocation = bitmap.PixelWidth * y + x;
int pixel = bitmap.Pixels[pixelLocation];
byte[] pixBytes = BitConverter.GetBytes(pixel);
//每一個都除3
byte bnwPixel = (byte)(.333 * pixBytes[2] + .333 * pixBytes[1] + .333 * pixBytes[0]);

pixBytes[0] = bnwPixel;//b
pixBytes[1] = bnwPixel;//g
pixBytes[2] = bnwPixel;//r

bitmap.Pixels[pixelLocation] = BitConverter.ToInt32(pixBytes, 0);
}
}
this.m_image.Source = bitmap;



如何处理就可以把黑色部分去掉呢?
roberqwe 2012-02-10
  • 打赏
  • 举报
回复
若是 过滤掉黑色部分 呢?
zz05962860978 2012-02-10
  • 打赏
  • 举报
回复
给你个参考,这是判断是否点击在图标的透明处的逻辑:
public bool IsClickEmpty(Point pp)
{
WriteableBitmap m_BitmapLog = new WriteableBitmap(T_ButtonImage.Source as BitmapSource);
int x = (int)pp.Y;
int y = (int)pp.X;
int id = x * m_BitmapLog.PixelWidth + y;
if (id > -1 && id < m_BitmapLog.Pixels.Length)
{
if (m_BitmapLog.Pixels[id] == BitConverter.ToInt32(new byte[4] { 0, 0, 0, 0 }, 0))//new byte[4] { 0, 0, 0, 0 } 这里是:ARBG顺序
return true;
}
else
return true;
return false;
}
roberqwe 2012-02-10
  • 打赏
  • 举报
回复
请教了!

8,757

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧