PNG图片透明度处理,边角毛糙的问题,如何解决?

wszhoho 2008-12-18 05:11:39
原始png图片:


程序透明处理掉Color.White的像素后的截图:


非常的毛糙,C#加AlphaBlend函数处理的,不知道一般是怎么做的,望指点一二,先谢过!!!
...全文
1265 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenhaohf 2009-04-20
  • 打赏
  • 举报
回复
把背景颜色改的反差大一点

imageAttr.SetColorKey(yourImg.GetPixel(0, 0), yourImg.GetPixel(0, 0))
g.DrawImage(yourImg, New Rectangle(0, 0, yourImg.Width, yourImg.tqImg.Height), 0, 0, yourImg.Width, yourImg.Height, GraphicsUnit.Pixel, imageAttr)
itcoco 2008-12-29
  • 打赏
  • 举报
回复
学习
wszhoho 2008-12-19
  • 打赏
  • 举报
回复
谢谢! 突然发现OpenNETCF里居然有这个接口,不过这个更加的面向过程。
pcjbird 2008-12-19
  • 打赏
  • 举报
回复

public enum PixelFormatID : int
{
PixelFormatIndexed = 0x00010000, // Indexes into a palette
PixelFormatGDI = 0x00020000, // Is a GDI-supported format
PixelFormatAlpha = 0x00040000, // Has an alpha component
PixelFormatPAlpha = 0x00080000, // Pre-multiplied alpha
PixelFormatExtended = 0x00100000, // Extended color 16 bits/channel
PixelFormatCanonical = 0x00200000,
PixelFormatUndefined = 0,
PixelFormatDontCare = 0,
PixelFormat1bppIndexed = (1 | (1 << 8) | PixelFormatIndexed | PixelFormatGDI),
PixelFormat4bppIndexed = (2 | (4 << 8) | PixelFormatIndexed | PixelFormatGDI),
PixelFormat8bppIndexed = (3 | (8 << 8) | PixelFormatIndexed | PixelFormatGDI),
PixelFormat16bppRGB555 = (5 | (16 << 8) | PixelFormatGDI),
PixelFormat16bppRGB565 = (6 | (16 << 8) | PixelFormatGDI),
PixelFormat16bppARGB1555 = (7 | (16 << 8) | PixelFormatAlpha | PixelFormatGDI),
PixelFormat24bppRGB = (8 | (24 << 8) | PixelFormatGDI),
PixelFormat32bppRGB = (9 | (32 << 8) | PixelFormatGDI),
PixelFormat32bppARGB = (10 | (32 << 8) | PixelFormatAlpha | PixelFormatGDI | PixelFormatCanonical),
PixelFormat32bppPARGB = (11 | (32 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatGDI),
PixelFormat48bppRGB = (12 | (48 << 8) | PixelFormatExtended),
PixelFormat64bppARGB = (13 | (64 << 8) | PixelFormatAlpha | PixelFormatCanonical | PixelFormatExtended),
PixelFormat64bppPARGB = (14 | (64 << 8) | PixelFormatAlpha | PixelFormatPAlpha | PixelFormatExtended),
PixelFormatMax = 15
}

// Pulled from imaging.h in the Windows Mobile 5.0 Pocket PC SDK
public enum BufferDisposalFlag : int
{
BufferDisposalFlagNone,
BufferDisposalFlagGlobalFree,
BufferDisposalFlagCoTaskMemFree,
BufferDisposalFlagUnmapView
}

// Pulled from imaging.h in the Windows Mobile 5.0 Pocket PC SDK
public enum InterpolationHint : int
{
InterpolationHintDefault,
InterpolationHintNearestNeighbor,
InterpolationHintBilinear,
InterpolationHintAveraging,
InterpolationHintBicubic
}

// Pulled from imaging.h in the Windows Mobile 5.0 Pocket PC SDK
public struct ImageInfo
{
// I am being lazy here, I don't care at this point about the RawDataFormat GUID
public uint GuidPart1;
public uint GuidPart2;
public uint GuidPart3;
public uint GuidPart4;
public PixelFormatID pixelFormat;
public uint Width;
public uint Height;
public uint TileWidth;
public uint TileHeight;
public double Xdpi;
public double Ydpi;
public uint Flags;
}

// Pulled from imaging.h in the Windows Mobile 5.0 Pocket PC SDK
[ComImport, Guid("327ABDA7-072B-11D3-9D7B-0000F81EF32E"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[ComVisible(true)]
public interface IImagingFactory
{
uint CreateImageFromStream(); // This is a place holder
uint CreateImageFromFile(string filename, out IImage image);
// We need the MarshalAs attribute here to keep COM interop from sending the buffer down as a Safe Array.
uint CreateImageFromBuffer([MarshalAs(UnmanagedType.LPArray)] byte[] buffer, uint size, BufferDisposalFlag disposalFlag, out IImage image);
uint CreateNewBitmap(); // This is a place holder
uint CreateBitmapFromImage(); // This is a place holder
uint CreateBitmapFromBuffer(); // This is a place holder
uint CreateImageDecoder(); // This is a place holder
uint CreateImageEncoderToStream(); // This is a place holder
uint CreateImageEncoderToFile(); // This is a place holder
uint GetInstalledDecoders(); // This is a place holder
uint GetInstalledEncoders(); // This is a place holder
uint InstallImageCodec(); // This is a place holder
uint UninstallImageCodec(); // This is a place holder
}

// Pulled from imaging.h in the Windows Mobile 5.0 Pocket PC SDK
[ComImport, Guid("327ABDA9-072B-11D3-9D7B-0000F81EF32E"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[ComVisible(true)]
public interface IImage
{
uint GetPhysicalDimension(out Size size);
uint GetImageInfo(out ImageInfo info);
uint SetImageFlags(uint flags);
// "Correct" declaration: uint Draw(IntPtr hdc, ref Rectangle dstRect, ref Rectangle srcRect);
uint Draw(IntPtr hdc, ref Rectangle dstRect, IntPtr NULL);
uint PushIntoSink(); // This is a place holder
uint GetThumbnail(uint thumbWidth, uint thumbHeight, out IImage thumbImage);
}




IImage img;
/********************************************************************************************/
string path = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)+@"\images";
// Load the image with alpha data through Imaging.
IImagingFactory factory = (IImagingFactory)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("327ABDA8-072B-11D3-9D7B-0000F81EF32E")));
factory.CreateImageFromFile(path + @"\" + "XXX.png", out img);
/********************************************************************************************/

private void Form1_Paint(object sender, PaintEventArgs e)
{
IntPtr dstHDC = e.Graphics.GetHdc();
Rectangle rect = new Rectangle(0, 0, 140, 90);
img.Draw(dstHDC, ref rect, IntPtr.Zero);
e.Graphics.ReleaseHdc(dstHDC);
}

wszhoho 2008-12-19
  • 打赏
  • 举报
回复
关键是c#,不知道如何使用这个东东,偶初学,也不知道要import哪个dll的哪个函数。
pcjbird 2008-12-19
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 wszhoho 的回复:]
啊! 天啦,为什么我的不行?盼指教,谢谢了!!!!!
[/Quote]

不是告诉你用IImage COM组件了嘛。。。。。。。。。什么不行啊。。。。。不要用AlphaBlend。。。。
wszhoho 2008-12-19
  • 打赏
  • 举报
回复
啊! 天啦,为什么我的不行?盼指教,谢谢了!!!!!
pcjbird 2008-12-19
  • 打赏
  • 举报
回复
放心吧,就你上面那个图片,我看了用IImage COM组件肯定可以的。。。。




这就是我用你那个图画出来的效果,SmartPhone的,PPC是一样的。。。。
pcjbird 2008-12-19
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 BEYONDMA 的回复:]
GDI出现这种情况很正常,用IIMAGE COM应该也不解决问题,两种方案一个是提高你图片的质量这个没的说,二是尽量画方形的PIC。WM上不像SYMBIAN不支持矢量图,这种问题没有办法。除非你改用DSHOW。
[/Quote]


"用IIMAGE COM应该也不解决问题",你试过吗?肯定可以解决问题的。
beyondma 2008-12-19
  • 打赏
  • 举报
回复
GDI出现这种情况很正常,用IIMAGE COM应该也不解决问题,两种方案一个是提高你图片的质量这个没的说,二是尽量画方形的PIC。WM上不像SYMBIAN不支持矢量图,这种问题没有办法。除非你改用DSHOW。
wszhoho 2008-12-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 pcjbird 的回复:]
毛边是应为你图片本来就有毛边,只是原来的背景白色你都看不出来。
[/Quote]
我用的是天气秀的图片文件,它显示出来的是没有毛边的。
pcjbird 2008-12-18
  • 打赏
  • 举报
回复
毛边是应为你图片本来就有毛边,只是原来的背景白色你都看不出来。
pcjbird 2008-12-18
  • 打赏
  • 举报
回复
使用iimage com组件吧。。。
qqlpp 2008-12-18
  • 打赏
  • 举报
回复
友情up
HyperSnap 6.30.01 2008.03.18 1. 添加了一个新的捕捉视频覆盖方式 - 通过“捕捉”菜单的“启用视频或游戏捕捉...”启用它。一旦启用, 常规 HyperSnap 屏幕捕捉功能也可捕捉视频图像。 2. 文本和水印对话框现在能够记住上次使用的文本对齐选项 (比如居中或左对齐文本) 3. 修正了一个打印预览错误 HyperSnap 6.21.04 2008.01.08 1. 修正了文本捕捉功能里 "使用自动滚动捕捉文本" 的其它问题 - 无法使用鼠标滚轮自动滚动窗口 HyperSnap 6.21.03 1. 修正了文本捕捉功能里面的 "使用自动滚动捕捉文本" HyperSnap 6.21.02 2007.08.17 1. 修正了一个问题 - 当使用某些非标准鼠标滚轮设置时, 自动滚动不工作 HyperSnap 6.21.01 2007.07.17 1. 添加了一个关闭 Vista 透明度的选项 (捕捉窗口和活动窗口时)。 2. 修正了打印功能中“打印范围”忽略了“到:”设置、以及打印所有页面直到结尾, 而不管你输入的是什么的问题。 3. 捕捉/窗口功能现在排除了垂直滚动条 (如果你在 Internet Explorer 7 文档中点击)。 HyperSnap 6.20.01 2007.06.28 1. 在绘制选项添加了线段平滑。 2. 添加了点状和破折号线段样式。 3. 捕捉光标处对象的文本命令现在有了一个新的选项,即允许捕捉时自动滚动。 4. 修正并改进了一些问题。 HyperSnap 6.13.02 2007.02.09 1. 改善了 Tab 定界文本捕捉 (某些列中空白的字段)。 2. 修正了文本捕捉的行间距问题 (有时插入了 2 个空行而不是 1 个)。 3. 修正了 Vista 下水印列表对话框问题。 4. 修正了从扫描仪获取图像时的内存漏洞。 HyperSnap 6.13.01 2007.02.05 1. 修正了在 Vista 的 Aero-Glass 界面下不能正确捕捉窗口真正形状 (例如圆形边角) 的问题。 2. 修正了在一幅图上平铺捕捉到的多图 (在“捕捉设置”的“查看 & 编辑”选项卡) 的问题。首次捕捉时, 如果 HyperSnap 窗口没有任何图像, 则进行正常捕捉, 代替了将捕捉到的图像追加到一个空的新图。 3. 修正了 JPEG 读取代码, 使得 HyperSnap 能够正确地的读取某些非常罕见的图象而不会崩溃。 HyperSnap v6.12.02 2006.12.20 1. 修正了在 Windows 98 下文件/打开功能的问题。 2. 修正了无法捕捉扩展活动窗口的问题。 HyperSnap v6.12.01 2006.12.13 1. 更新了自动滚动,支持 Office 2007 (Word 和 Excel) 2. 更新了文本捕捉,支持 Vista RTM 32 位和 64 位版本 3. 新增了一个选项“复制链接地址到剪贴板...” (在“文件/上传到 FTP 服务器...”)。选定后, 你可以定义一个文本 (可包含宏,如: 文件名称和路径、图像宽度和高度等), 当成功地上传到 FTP 后,它们将被复制到剪贴板以便粘贴到 HTML 编辑器中。 4. 新增了一个宏命令: %compname% (在文本和水印编辑, 以及打印页眉和页脚)。如果你在这些地方输入 %compname%, 它将扩大为当前计算机名称。 HyperSnap v6.11.02 2006.10.09 1. 修正了不能在 Windows 98 或其它旧版本的 Windows 下进行屏幕捕捉的错误。 HyperSnap v6.11.01 2006-09-27 1. 兼容于 Windows Vista RC1 2.“文本捕捉”现在也能在 Vista 64 位处理器版本上使用 HyperSnap v6.10.02 2006-08-16 1. 允许更改将捕捉的图像自动粘贴到其它应用程序的快捷键。但当前没有用户界面编辑这些键, 它们只能在注册表中更改。如果你需要这个功能, 请联系 Hyperionics 技术支持。 2. 修正了以“2 比特/像素”的颜色格式打开 PNG 文件时出现的问题。 3. 修正了 -snap:window 选项的命令行处理 - 如果被取消, 常会显示错误信息而不是静默退出。 4. 修正了双击后不必要的文本对象或水印重迭 - 取消文本或水印编辑并试图移动对象。 HyperSnap v6.10.01 2006-07-14 1. 在捕捉设置的“复制和打印”标签新增了一个选项, 捕捉并粘贴后, 最小化应用程序窗口, 自动粘贴捕捉的图像或文本到窗口。 2. 对“编辑/粘贴为新图像”功能进行了细微修正, 从 MS Word 复制的图像粘贴为 8-bit 图像时, 现在它会自动选择最佳颜色分辨率图像。 HyperSnap v6.10.00 2006-06-22 TextSnap(tm) 文本捕捉的增强和更改: 1.“文本捕捉”从“捕捉”菜单移出为新的“文本捕捉”菜单 (在“选项”前面) 2. 新增两个文本捕捉功能: “捕捉自动滚动窗口文本”和“捕捉自动滚动区域文本”(允许使用垂直滚动条)。 3. 新增文本捕捉模式: 制表站定界数据捕捉 (粘贴到空白表格) – 在捕捉设置的“文本捕捉”选项卡。 4. 在“文本捕捉”菜单, 新的文本捕捉设置项目允许你快速访问捕捉设置的“文本捕捉”选项卡。 5.“快速文本捕捉模式”设置从“捕捉”设置的“文本捕捉”选项卡移出为新的“文本捕捉热键”(在文本捕捉菜单)。 6. 通过修正, 使得“文本捕捉”可运行在 MS Windows Vista Beta 2 上。 其它更改 1.“选项”菜单中的“配置热键”分为两个: “屏幕捕捉热键”现在放于“捕捉”菜单, “文本捕捉热键”放在“文本捕捉”菜单。 2. 图像/阴影功能现在有了新的阴影方向设置, 新增了“自动添加此阴影到最新绘制图形”选项。此设置也可以通过点击顶端工具栏的“切换目标阴影”按钮启用。启用后, 任何你绘制的图形都可以有阴影。 3. 箭头样式现在包含双向箭头

7,655

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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