WPF九宫格HLSL版

  偶遇需要再WPF里面处理九宫格,因不喜截图缩放,即写成了HLSL的Effcect

 

sampler2D input : register(s0);

/// <summary>The float of the Left.</summary>
/// <minValue>1</minValue>
/// <maxValue>20</maxValue>
/// <defaultValue>20</defaultValue>
float Left : register(C0);

/// <summary>The float of the Top.</summary>
/// <minValue>1</minValue>
/// <maxValue>20</maxValue>
/// <defaultValue>20</defaultValue>
float Top : register(C1);

/// <summary>The float of the Right.</summary>
/// <minValue>1</minValue>
/// <maxValue>20</maxValue>
/// <defaultValue>20</defaultValue>
float Right : register(C2);

/// <summary>The float of the Bottom.</summary>
/// <minValue>1</minValue>
/// <maxValue>20</maxValue>
/// <defaultValue>20</defaultValue>
float Bottom : register(C3);

/// <summary>The float of the Width.</summary>
/// <minValue>5</minValue>
/// <maxValue>200</maxValue>
/// <defaultValue>46</defaultValue>
float Width : register(C4);

/// <summary>The float of the Height.</summary>
/// <minValue>5</minValue>
/// <maxValue>200</maxValue>
/// <defaultValue>46</defaultValue>
float Height : register(C5);

/// <summary>The float of the ShowWidth.</summary>
/// <minValue>50</minValue>
/// <maxValue>1200</maxValue>
/// <defaultValue>750</defaultValue>
float ShowWidth : register(C6);

/// <summary>The float of the ShowHeight.</summary>
/// <minValue>50</minValue>
/// <maxValue>1200</maxValue>
/// <defaultValue>700</defaultValue>
float ShowHeight : register(C7);

float4 main(float2 uv : TEXCOORD) : COLOR 
{ 

    float realwidth = uv.x * ShowWidth;
    float realheight = uv.y * ShowHeight;

    //Set color of no scale
    float x = uv.x * ShowWidth / Width;
    float y = uv.y * ShowHeight / Height;

    //Scale X
    if(realwidth >= Left && realwidth <= (ShowWidth - Right))
    {
        x = ((uv.x * ShowWidth - Left) / (ShowWidth - Left - Right) * (Width - Left - Right) + Left) / Width;
    }
    // Real color of max x
    else if(realwidth > (ShowWidth - Right) )
    {
        x = 1 - (1- uv.x) * ShowWidth / Width;
    }

    //Scale Y
    if(realheight >= Top && realheight <= ShowHeight - Bottom )
    {
        y = ((uv.y * ShowHeight - Top) / (ShowHeight - Top - Bottom) * (Height - Top - Bottom) + Top ) / Height;
    }
    //Real color of max y
    else if(realheight > ShowHeight - Bottom )  
    {
        y =  1 - (1- uv.y) * ShowHeight / Height;
    }

    return tex2D(input, float2(x ,y)) ;
}
View Code

 

转载于:https://www.cnblogs.com/jiailiuyan/p/4838448.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值