方法一(CSS滤镜,某些时候不管用):

_background: url(http://www.snowangel.cn/images/angel.png) no-repeat !important;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=noscale, src="http://www.snowangel.cn/images/angel.png");
_background:none;

方法二:(引用js工具类,成功)

var DD_belatedPNG={ns:"DD_belatedPNG",imgSize:{},delay:10,nodesFixed:0,createVmlNameSpace:function(){if(document.namespaces&&!document.namespaces[this.ns]){document.namespaces.add(this.ns,"urn:schemas-microsoft-com:vml")}},createVmlStyleSheet:function(){var b,a;b=document.createElement("style");b.setAttribute("media","screen");document.documentElement.firstChild.insertBefore(b,document.documentElement.firstChild.firstChild);if(b.styleSheet){b=b.styleSheet;b.addRule(this.ns+"\\:*","{behavior:url(#default#VML)}");b.addRule(this.ns+"\\:shape","position:absolute;");b.addRule("img."+this.ns+"_sizeFinder","behavior:none; border:none; position:absolute; z-index:-1; top:-10000px; visibility:hidden;");this.screenStyleSheet=b;a=document.createElement("style");a.setAttribute("media","print");document.documentElement.firstChild.insertBefore(a,document.documentElement.firstChild.firstChild);a=a.styleSheet;a.addRule(this.ns+"\\:*","{display: none !important;}");a.addRule("img."+this.ns+"_sizeFinder","{display: none !important;}")}},readPropertyChange:function(){var b,c,a;b=event.srcElement;if(!b.vmlInitiated){return}if(event.propertyName.search("background")!=-1||event.propertyName.search("border")!=-1){DD_belatedPNG.applyVML(b)}if(event.propertyName=="style.display"){c=(b.currentStyle.display=="none")?"none":"block";for(a in b.vml){if(b.vml.hasOwnProperty(a)){b.vml[a].shape.style.display=c}}}if(event.propertyName.search("filter")!=-1){DD_belatedPNG.vmlOpacity(b)}},vmlOpacity:function(b){if(b.currentStyle.filter.search("lpha")!=-1){var a=b.currentStyle.filter;a=parseInt(a.substring(a.lastIndexOf("=")+1,a.lastIndexOf(")")),10)/100;b.vml.color.shape.style.filter=b.currentStyle.filter;b.vml.image.fill.opacity=a}},handlePseudoHover:function(a){setTimeout(function(){DD_belatedPNG.applyVML(a)},1)},fix:function(a){if(this.screenStyleSheet){var c,b;c=a.split(",");for(b=0;b<c.length;b++){this.screenStyleSheet.addRule(c[b],"behavior:expression(DD_belatedPNG.fixPng(this))")}}},applyVML:function(a){a.runtimeStyle.cssText="";this.vmlFill(a);this.vmlOffsets(a);this.vmlOpacity(a);if(a.isImg){this.copyImageBorders(a)}},attachHandlers:function(i){var d,c,g,e,b,f;d=this;c={resize:"vmlOffsets",move:"vmlOffsets"};if(i.nodeName=="A"){e={mouseleave:"handlePseudoHover",mouseenter:"handlePseudoHover",focus:"handlePseudoHover",blur:"handlePseudoHover"};for(b in e){if(e.hasOwnProperty(b)){c[b]=e[b]}}}for(f in c){if(c.hasOwnProperty(f)){g=function(){d[c[f]](i)};i.attachEvent("on"+f,g)}}i.attachEvent("onpropertychange",this.readPropertyChange)},giveLayout:function(a){a.style.zoom=1;if(a.currentStyle.position=="static"){a.style.position="relative"}},copyImageBorders:function(b){var c,a;c={borderStyle:true,borderWidth:true,borderColor:true};for(a in c){if(c.hasOwnProperty(a)){b.vml.color.shape.style[a]=b.currentStyle[a]}}},vmlFill:function(e){if(!e.currentStyle){return}else{var d,f,g,b,a,c;d=e.currentStyle}for(b in e.vml){if(e.vml.hasOwnProperty(b)){e.vml[b].shape.style.zIndex=d.zIndex}}e.runtimeStyle.backgroundColor="";e.runtimeStyle.backgroundImage="";f=true;if(d.backgroundImage!="none"||e.isImg){if(!e.isImg){e.vmlBg=d.backgroundImage;e.vmlBg=e.vmlBg.substr(5,e.vmlBg.lastIndexOf('")')-5)}else{e.vmlBg=e.src}g=this;if(!g.imgSize[e.vmlBg]){a=document.createElement("img");g.imgSize[e.vmlBg]=a;a.className=g.ns+"_sizeFinder";a.runtimeStyle.cssText="behavior:none; position:absolute; left:-10000px; top:-10000px; border:none; margin:0; padding:0;";c=function(){this.width=this.offsetWidth;this.height=this.offsetHeight;g.vmlOffsets(e)};a.attachEvent("onload",c);a.src=e.vmlBg;a.removeAttribute("width");a.removeAttribute("height");document.body.insertBefore(a,document.body.firstChild)}e.vml.image.fill.src=e.vmlBg;f=false}e.vml.image.fill.on=!f;e.vml.image.fill.color="none";e.vml.color.shape.style.backgroundColor=d.backgroundColor;e.runtimeStyle.backgroundImage="none";e.runtimeStyle.backgroundColor="transparent"},vmlOffsets:function(d){var h,n,a,e,g,m,f,l,j,i,k;h=d.currentStyle;n={W:d.clientWidth+1,H:d.clientHeight+1,w:this.imgSize[d.vmlBg].width,h:this.imgSize[d.vmlBg].height,L:d.offsetLeft,T:d.offsetTop,bLW:d.clientLeft,bTW:d.clientTop};a=(n.L+n.bLW==1)?1:0;e=function(b,p,q,c,s,u){b.coordsize=c+","+s;b.coordorigin=u+","+u;b.path="m0,0l"+c+",0l"+c+","+s+"l0,"+s+" xe";b.style.width=c+"px";b.style.height=s+"px";b.style.left=p+"px";b.style.top=q+"px"};e(d.vml.color.shape,(n.L+(d.isImg?0:n.bLW)),(n.T+(d.isImg?0:n.bTW)),(n.W-1),(n.H-1),0);e(d.vml.image.shape,(n.L+n.bLW),(n.T+n.bTW),(n.W),(n.H),1);g={X:0,Y:0};if(d.isImg){g.X=parseInt(h.paddingLeft,10)+1;g.Y=parseInt(h.paddingTop,10)+1}else{for(j in g){if(g.hasOwnProperty(j)){this.figurePercentage(g,n,j,h["backgroundPosition"+j])}}}d.vml.image.fill.position=(g.X/n.W)+","+(g.Y/n.H);m=h.backgroundRepeat;f={T:1,R:n.W+a,B:n.H,L:1+a};l={X:{b1:"L",b2:"R",d:"W"},Y:{b1:"T",b2:"B",d:"H"}};if(m!="repeat"||d.isImg){i={T:(g.Y),R:(g.X+n.w),B:(g.Y+n.h),L:(g.X)};if(m.search("repeat-")!=-1){k=m.split("repeat-")[1].toUpperCase();i[l[k].b1]=1;i[l[k].b2]=n[l[k].d]}if(i.B>n.H){i.B=n.H}d.vml.image.shape.style.clip="rect("+i.T+"px "+(i.R+a)+"px "+i.B+"px "+(i.L+a)+"px)"}else{d.vml.image.shape.style.clip="rect("+f.T+"px "+f.R+"px "+f.B+"px "+f.L+"px)"}},figurePercentage:function(d,c,f,a){var b,e;e=true;b=(f=="X");switch(a){case"left":case"top":d[f]=0;break;case"center":d[f]=0.5;break;case"right":case"bottom":d[f]=1;break;default:if(a.search("%")!=-1){d[f]=parseInt(a,10)/100}else{e=false}}d[f]=Math.ceil(e?((c[b?"W":"H"]*d[f])-(c[b?"w":"h"]*d[f])):parseInt(a,10));if(d[f]%2===0){d[f]++}return d[f]},fixPng:function(c){c.style.behavior="none";var g,b,f,a,d;if(c.nodeName=="BODY"||c.nodeName=="TD"||c.nodeName=="TR"){return}c.isImg=false;if(c.nodeName=="IMG"){if(c.src.toLowerCase().search(/\.png$/)!=-1){c.isImg=true;c.style.visibility="hidden"}else{return}}else{if(c.currentStyle.backgroundImage.toLowerCase().search(".png")==-1){return}}g=DD_belatedPNG;c.vml={color:{},image:{}};b={shape:{},fill:{}};for(a in c.vml){if(c.vml.hasOwnProperty(a)){for(d in b){if(b.hasOwnProperty(d)){f=g.ns+":"+d;c.vml[a][d]=document.createElement(f)}}c.vml[a].shape.stroked=false;c.vml[a].shape.appendChild(c.vml[a].fill);c.parentNode.insertBefore(c.vml[a].shape,c)}}c.vml.image.shape.fillcolor="none";c.vml.image.fill.type="tile";c.vml.color.fill.on=false;g.attachHandlers(c);g.giveLayout(c);g.giveLayout(c.offsetParent);c.vmlInitiated=true;g.applyVML(c)}};try{document.execCommand("BackgroundImageCache",false,true)}catch(r){}DD_belatedPNG.createVmlNameSpace();DD_belatedPNG.createVmlStyleSheet();

调用方式(fix里面的参数为css类):
window.onload = function()
{
 DD_belatedPNG.fix(".msg0,.msg");
}

转载于:https://www.cnblogs.com/lben/archive/2013/01/15/2861231.html

png格式图片背景不透明问题解决相关推荐

  1. OpenCV技巧 | 常用格式图片保存为透明背景图片(附Python源码)-教你轻松制作Logo

    导读 本文主要介绍使用OpenCV将常用格式图片保存为透明背景图片的方法与实现代码. 实现目标 本文的目标有如下两个: ① 将常见格式[jpg/png/bmp]白色背景图片转换保存为透明背景图片: ② ...

  2. html2canvas 图片合成模糊以及保存为图片背景图丢失问题解决

    html2canvas 图片合成模糊以及保存为图片背景图丢失问题解决 注意 作为背景的图片必须放在服务器,存放在本地会出现截图的时候背景图丢失的问题; 背景图必须放在img里面里面,通过定位处理成和背 ...

  3. 怎么将素材图片背景变透明?如何一键抠除图片背景?

    我们在提取一些素材图片的时候,可能会因为图片格式等原因,使原本背景透明图片变成了纯色背景图片.这时候我们需要使用抠图功能去除图片背景色,但是对不会用ps的小伙伴来说将图片背景变透明就比较困难了,所以小 ...

  4. 怎么把背景图片变透明html,怎样把图片背景变成透明

    大家好,我是时间财富网智能客服时间君,上述问题将由我为大家进行解答. 以Photoshop软件为例,把图片背景变成透明的方法是: 1.首先,打开电脑中的Photoshop软件,进入主界面: 2.在Ph ...

  5. C#  图片背景变为透明

    C#  图片背景变为透明 今天遇到从身份证读取信息粘贴到身份证模板身份身份证图片的需求,但是获取的身份证头像是带背景色的所以需要去掉背景色.CSDN找了半天都是bitmap.MakeTranspare ...

  6. 图片如何去掉背景色?如何使图片背景变透明?

    图片设计工作者常常需要用透明背景图片,如果下载的图片素材不是透明背景的话,就需要先用图片处理工具将图片背景变透明.下面我们就使用压缩图的图片去底色(https://www.yasuotu.com/bu ...

  7. png变成矢量图_[PPT]如何将图片背景变成透明

    说好今天要介绍一下PNG图,PNG是什么? 是Portable Network Graphics的缩写,中文意思是可携式网络图像.具体PNG的各种解释小伙伴们可以自己去找度娘. 为什么要介绍PNG格式 ...

  8. 利用OpenCV识别图片背景是否透明

    因为公司的需求,有几百万张图片需要识别,筛选出背景是透明的图片,我上网找了一圈也没看到成熟的方案,于是自己想了一个比较简陋但是还算是挺好用的方案. 大概的图片就是这些种类吧,图一图三是我想要筛选出来的 ...

  9. 如何用技术手段将图片背景变为透明?

    咪哥杂谈 本篇阅读时间约为 6 分钟. 1 前言 上周给大家分享了人脸识别的一个 Python 库.今天来继续讲讲我上次在评论区留言的后续. 既然是追热点的需求,大家可以想想,近几年发生在身边的热点事 ...

最新文章

  1. SQL 关于apply的两种形式cross apply 和 outer apply
  2. 如何看服务器java_如何查看Windows服务器运行了多长时间
  3. java 时间格式化_彻底解决Spring mvc中时间的转换和序列化等问题
  4. Spring事务管理--嵌套事务详解
  5. rabbitmq 取消消息_SpringBoot整合RabbitMQ实现延迟消息
  6. Java RandomAccessFile readInt()方法与示例
  7. 百度文库文档 下载券文档 代下载 原格式不变
  8. cAdvisor源码分析
  9. 商业计划书 创业者的“必修课程”
  10. 重启计算机找不到打印机,如何解决重启后打印机找不到设备
  11. FPGA写约束文件+固化+上板抓信号方法(vivado软件)
  12. C++ 次方/次幂函数
  13. 台式计算机能装蓝牙吗,台式机安装蓝牙方法推荐
  14. android源码分析
  15. node对文件的读取和修改
  16. python小程序嵌入excel_用原生的方式操作Excel,Python玩转Excel神器xlsxwriter详解!...
  17. 欧冠超级计算机,超级计算机预测欧冠决赛:红军65%概率夺冠 萨拉赫最可能进球...
  18. 韩信点兵 中国剩余定理
  19. Nature子刊:基于海马功能连接预测模型预测个体对压力的主观感受
  20. 通过RK3568实现的NVR方案

热门文章

  1. 数据库 网状模型和层次模型
  2. android中留言板功能,js 实现简易留言板功能
  3. win7官方原版iso镜像_建议收藏!微软 Win10 版本 2004 正式版官方 ISO 镜像下载大全...
  4. 《大数据讲堂》:世平信息首席科学家吕喆谈数据治理的落地措施
  5. 分享Android KTX + Kotlin协程 组合使用
  6. 落谷:P1004:方格取数
  7. bert中文短文本句向量生成、相似度计算(GPU版、windows、win10、linux、django和flask可用)
  8. Visual C++/MFC入门教程
  9. 某农业学校python(二)
  10. 数据结构与算法:树(Tree)