博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在Windows Mobile下使用.NET Compact Framework画透明图片
阅读量:4312 次
发布时间:2019-06-06

本文共 1138 字,大约阅读时间需要 3 分钟。

Iphone之所以那么流行一部分归功于他的炫丽的界面,其实那些界面的实现主要由两大功能组成:画透明图片和画渐变效果。这次主要讲述windows mobile下画透明图片。

所谓透明图片其实就是把图片背景设置成透明,如果直接画出图片会显示一个规则正方形的图,其中图片包括不规则图形和该图像下的背景,所以如果只是想画出不规则图形,需要把背景去掉。下面为去掉背景的实现。

///          /// Draws the image with transparency ///          /// Destination graphics         /// The image to draw         /// Desctination rectangle public static void DrawImageTransparent(this Graphics gx, Image image, Rectangle destRect)         {
ImageAttributes imageAttr = new ImageAttributes(); Color transpColor = GetTransparentColor(image); imageAttr.SetColorKey(transpColor, transpColor); gx.DrawImage(image, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttr); imageAttr.Dispose(); }
private static Color GetTransparentColor(Image image)         {
return ((Bitmap)image).GetPixel(image.Width - 1, image.Height - 1); }

先调用Bitmap.GetPixel()函数取出图片的背景信息,然后设置ImageAttributes 的属性,在画图的时候把图片属性传递到Graphics.DrawImage()函数进行绘画。

效果图如下:

 

有些图片做的不好,有点锯齿。

 下面是没有去掉背景的图片,作为比较。

转载于:https://www.cnblogs.com/procoder/archive/2009/08/13/Windows_Mobile_Compact_Framework_Transparent.html

你可能感兴趣的文章
PHP语法2
查看>>
python unittest学习1---重要的几个概念
查看>>
MapReduce编程之Reduce Join多种应用场景与使用
查看>>
干货: 可视化项目实战经验分享,轻松玩转 Bokeh (建议收藏)
查看>>
使用pyinstaller打包多个py文件为一个EXE文件
查看>>
书接前文,用多进程模式实现fibonnachi并发计算
查看>>
numpy的数组常用运算练习
查看>>
ExtJs之DHTML,DOM,EXTJS的事件绑定区别
查看>>
Leetcode:Toeplitz Matrix
查看>>
js定时器
查看>>
Android官方文档
查看>>
tcp/udp协议代码实现
查看>>
python---django中orm的使用(2)
查看>>
读书时间《JavaScript高级程序设计》四:BOM,客户端检测
查看>>
Linux基础命令---free显示内存使用
查看>>
转:CentOS---网络配置详解
查看>>
绕任意单位轴旋转矩阵计算
查看>>
洛谷P2502[HAOI2006]旅行
查看>>
Linux 配置mail发送邮件
查看>>
Linux 正则
查看>>