在C#上的MouseClick上模糊图像

时间:2017-09-11 23:16:08

标签: c# forms mouseevent mouse blur

所以我有这个带有图片框的表格,我的想法是当我点击它时模糊光标周围的图像。有什么想法吗?

当它只是模糊整个图像时,它在另一台电脑上工作,我添加的只是鼠标位置的东西,它似乎没有做任何事情。

public partial class Form1 : Form
{
    Bitmap newBitmap;
    Image file;
    int blurAmount = 5 ;
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        DialogResult dr = openFileDialog1.ShowDialog();
        if (dr == DialogResult.OK)
        {
            file = Image.FromFile(openFileDialog1.FileName);
            newBitmap = new Bitmap(openFileDialog1.FileName);

            pictureBox1.Image=file;
        }

    }

    private void Form1_MouseClick(object sender, MouseEventArgs e)
    {

        for (int x = e.Location.X-25; x < e.Location.X+25; x++)
            {
                for (int y =e.Location.Y-25; y < e.Location.Y+25; y++)
                {
                    try
                    {
                        Color prevX = newBitmap.GetPixel(x - blurAmount, y);
                        Color nextX = newBitmap.GetPixel(x + blurAmount, y);
                        Color prevY = newBitmap.GetPixel(x, y - blurAmount);
                        Color nextY = newBitmap.GetPixel(x, y + blurAmount);

                        int avgR = (int)((prevX.R + nextX.R + prevY.R + nextY.R) / 4);
                        int avgG = (int)((prevX.G + nextX.G + prevY.G + nextY.G) / 4);
                        int avgB = (int)((prevX.B + nextX.B + prevY.B + nextY.B) / 4);

                        newBitmap.SetPixel(x, y, Color.FromArgb(avgR, avgG, avgB));
                    }
                    catch (Exception) {}
                }
            }
           pictureBox1.Image = newBitmap;
        }
}

1 个答案:

答案 0 :(得分:0)

我为 pictureBox 设置了点击事件并且工作正常

def searchUserSynapse(request):
    currentUser = loggedInUser(request)
    currentProfile = Profile.objects.get(user = currentUser)
    synapse_id = currentProfile.synapse_id

    user = SynapseUser.by_id(clients, str(synapse_id))

    response = user.json
    print(response)
    return user

def linkBankLogin(request, form):
    currentUser = loggedInUser(request)
    cd = form.cleaned_data
    bank_name = cd['bank']
    username = cd['username']
    password = cd['password']

    required = {
        'bank_name':'wellsfargo',
        'username':'omarjandali',
        'password':'123123asd'
    }

    response = searchUserSynapse(request)

    ach_us = AchUsNode.create_via_bank_login(response, **required)

    ach_us.mfa_verified