简体   繁体   English

将图像1的像素设置为透明以显示图像1后面的图像

[英]Setting pixel of image 1 to transparent to show image behind image 1

The program that I am working on requires that I layer two images on top of each other (z indexes will be 1 number apart). 我正在处理的程序要求我将两个图像叠加在一起(z索引将相隔1个数字)。 The top layer is a black image(png) and the bottom layer is a normal image that you would pull from google. 顶层是黑色图像(png),底层是您从谷歌中提取的普通图像。 Let's say I pull a set of pixels from a database that had been previously entered(100 pixels for example); 假设我从先前输入的数据库中拉出一组像素(例如100像素); I want those 100 pixels to turn transparent. 我希望这100个像素变成透明的。 My current code is responding by changing the pixel to plain white. 我当前的代码是通过将像素更改为纯白色来响应。 Anyone have any suggestions? 有人有什么建议吗?

This code snippet represents specific pixels being pulled from a database. 此代码段表示从数据库中提取的特定像素。

DataSet ds = new DataSet();
        SqlCommand sqlRead = new SqlCommand("SELECT * FROM PIXEL", con);
        List<int> pixelIds = new List<int>();

        using (SqlDataReader read = sqlRead.ExecuteReader())
        {
            while (read.Read())
            {
                int pixel = Convert.ToInt32(read[0]);
                pixelIds.Add(pixel);
                int yaxis = Convert.ToInt32(pixel) / 1000;
                int xaxis = Convert.ToInt32(pixel) % 1000;
                image1.SetPixel(xaxis, yaxis, Color.Transparent);
            }
        }

Solved. 解决了。 What I had to do was change the Color.Transparent to Color.Brown then wrote image1.MakeTransparent(Color.Brown) below that which worked perfectly. 我需要做的就是改变Color.TransparentColor.Brown然后写image1.MakeTransparent(Color.Brown)低于其完美。 Thank you all for the responses. 谢谢大家的回复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM