<template>
<div :style="`width:${width}px;height:${height}px`">
<img :src="imgSrc" v-if="!isGray||!isIE11">
<div v-else>
<svg overflow="hidden" preserveAspectRatio="none slice" :width="width" :height="height">
<image overflow="visible" preserveAspectRatio="none slice" x='0' y='0' :width="width" :height="height" :xlink:href="imgSrc" filter="url(#grayscle)"></image>
</svg>
</div>
</div>
</template>
<script>
export default {
name:"grayImg",
props:{
imgSrc:{
type:String,
default:""
},
width:{
type:[Number,String],
default:150
},
height:{
type:[Number,String],
default:90
}
},
computed: {
isGray() {
return window.sessionStorage.getItem('skin')=='default';
},
isIE11(){
return navigator.userAgent.indexOf('Trident')!==-1;
}
},
}
</script>
<style lang="scss" scoped>
img{
height:100%;
width:100%;
}
</style>
// <template>
// <svg xmlns=" http://www.w3.org/2000/svg" style="display:none">
// <filter id="grayscale">
// <feColorMatrix type="matrix"values="0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0"/>
// </filter>
// </svg>
// </template>
// <script>
// export default {
// name:"grayscale"
// }
// </script>
it图片过滤灰色兼容
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 网上搜索了一下,没找的Swift版本,于是照着Objective-C翻译了一遍,给UIImage写了个扩展,现贴出...
- MagicPureGrayOutput github地址:https://github.com/SmileZXLe...
- 效果实现的代码是鉴于上一片的博客,这里只需要修改片元着色器实现滤镜效果,因此对于实现的代码将不阐述,具体代码,可以...