Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ASP.net中反转图像透明度_Asp.net_Image Processing - Fatal编程技术网

在ASP.net中反转图像透明度

在ASP.net中反转图像透明度,asp.net,image-processing,Asp.net,Image Processing,我正试图建立一个网页,将允许我采取一个输入图像和生成一个面具从它。输入将是一个带有透明背景的索引PNG。如果原始图像是透明的,则生成的图像将是黑色的;如果原始图像是不透明的,则生成的图像将是透明的 我在asp.net中做了一些非常基本的图像处理,但我不确定如何继续。我希望有比逐像素更快的解决方案 如果有人能给我指出正确的方向,我将非常感激 您可能应该研究转换 您可能应该研究转换 好的,我有一个使用转换的工作解决方案。说实话,我并不是100%理解我在用颜色矩阵做什么——所以我这样做的方式可能不太理

我正试图建立一个网页,将允许我采取一个输入图像和生成一个面具从它。输入将是一个带有透明背景的索引PNG。如果原始图像是透明的,则生成的图像将是黑色的;如果原始图像是不透明的,则生成的图像将是透明的

我在asp.net中做了一些非常基本的图像处理,但我不确定如何继续。我希望有比逐像素更快的解决方案


如果有人能给我指出正确的方向,我将非常感激

您可能应该研究转换


您可能应该研究转换


好的,我有一个使用转换的工作解决方案。说实话,我并不是100%理解我在用颜色矩阵做什么——所以我这样做的方式可能不太理想。下面粘贴的代码,以防其他人遇到相同的问题

基本上,变换使透明像素变黑,彩色像素变白。然后我在白色像素上使用MakeTransparent。应该有一种方法可以在一个步骤中做到这一点,但不幸的是,今天我无法做到这一点

再次感谢克里斯-我花了好几个小时寻找一种可行的技术,但在这种类型的转换上我没有遇到任何东西

<%@ page language="vb" contenttype="image/png" %>

<%@ Import Namespace="System.IO" %>
<%@ import namespace="system.drawing" %>
<%@ import namespace="system.drawing.imaging" %>
<%@ import namespace="system.drawing.drawing2d" %>

<script runat="server">
    Sub Page_Load()
        Dim tmpImage As Bitmap = Bitmap.FromFile(Server.MapPath("test.png"))
        Dim input As Bitmap = New Bitmap(tmpImage.Width, tmpImage.Height, PixelFormat.Format32bppArgb)


        Dim trans As New ColorMatrix(New Single()() _
                       {New Single() {0, 1, 1, 1, 0}, _
                        New Single() {1, 0, 1, 1, 0}, _
                        New Single() {1, 1, 0, 1, 0}, _
                        New Single() {1, 1, 1, 1, 0}, _
                        New Single() {0, 0, 0,255, 1}})


        Dim attr As New ImageAttributes
        Dim rc As New Rectangle(0, 0, input.Width, input.Height)
        Dim out As New memorystream
        Dim g As Graphics = Graphics.FromImage(input)
        g.Clear(Color.Transparent)

        attr.SetColorMatrix(trans, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap)      
        g.DrawImage(tmpImage, rc, 0, 0, input.Width, input.Height, GraphicsUnit.Pixel, attr)
        input.makeTransparent(System.Drawing.Color.White)
        input.Save(out, ImageFormat.Png)
        g.Dispose()
        input.Dispose()
        tmpImage.Dispose()
        out.WriteTo(Response.OutputStream)
    End Sub

</script>

子页_加载()
Dim tmpImage As Bitmap=Bitmap.FromFile(Server.MapPath(“test.png”))
位图尺寸输入=新位图(tmpImage.Width、tmpImage.Height、PixelFormat.Format32bppArgb)
Dim trans作为新颜色矩阵(新单色)()_
{New Single(){0,1,1,1,0}_
新的Single(){1,0,1,1,0}_
新的Single(){1,1,0,1,0}_
新的Single(){1,1,1,0}_
新的Single(){0,0,0255,1})
Dim attr作为新的ImageAttributes
将rc标注为新矩形(0,0,输入.宽度,输入.高度)
变暗为新的记忆流
尺寸g作为图形=图形。从图像(输入)
g、 透明(彩色、透明)
attr.SetColorMatrix(trans,System.Drawing.Imaging.ColorMatrixFlag.Default,System.Drawing.Imaging.ColorAdjustType.Bitmap)
g、 DrawImage(tmpImage、rc、0、0、input.Width、input.Height、GraphicsUnit.Pixel、attr)
input.makeTransparent(System.Drawing.Color.White)
保存(输出,ImageFormat.Png)
g、 处置
input.Dispose()
tmpImage.Dispose()
WriteTo(Response.OutputStream)
端接头

好的,我有一个使用转换的工作解决方案。说实话,我并不是100%理解我在用颜色矩阵做什么——所以我这样做的方式可能不太理想。下面粘贴的代码,以防其他人遇到相同的问题

基本上,变换使透明像素变黑,彩色像素变白。然后我在白色像素上使用MakeTransparent。应该有一种方法可以在一个步骤中做到这一点,但不幸的是,今天我无法做到这一点

再次感谢克里斯-我花了好几个小时寻找一种可行的技术,但在这种类型的转换上我没有遇到任何东西

<%@ page language="vb" contenttype="image/png" %>

<%@ Import Namespace="System.IO" %>
<%@ import namespace="system.drawing" %>
<%@ import namespace="system.drawing.imaging" %>
<%@ import namespace="system.drawing.drawing2d" %>

<script runat="server">
    Sub Page_Load()
        Dim tmpImage As Bitmap = Bitmap.FromFile(Server.MapPath("test.png"))
        Dim input As Bitmap = New Bitmap(tmpImage.Width, tmpImage.Height, PixelFormat.Format32bppArgb)


        Dim trans As New ColorMatrix(New Single()() _
                       {New Single() {0, 1, 1, 1, 0}, _
                        New Single() {1, 0, 1, 1, 0}, _
                        New Single() {1, 1, 0, 1, 0}, _
                        New Single() {1, 1, 1, 1, 0}, _
                        New Single() {0, 0, 0,255, 1}})


        Dim attr As New ImageAttributes
        Dim rc As New Rectangle(0, 0, input.Width, input.Height)
        Dim out As New memorystream
        Dim g As Graphics = Graphics.FromImage(input)
        g.Clear(Color.Transparent)

        attr.SetColorMatrix(trans, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap)      
        g.DrawImage(tmpImage, rc, 0, 0, input.Width, input.Height, GraphicsUnit.Pixel, attr)
        input.makeTransparent(System.Drawing.Color.White)
        input.Save(out, ImageFormat.Png)
        g.Dispose()
        input.Dispose()
        tmpImage.Dispose()
        out.WriteTo(Response.OutputStream)
    End Sub

</script>

子页_加载()
Dim tmpImage As Bitmap=Bitmap.FromFile(Server.MapPath(“test.png”))
位图尺寸输入=新位图(tmpImage.Width、tmpImage.Height、PixelFormat.Format32bppArgb)
Dim trans作为新颜色矩阵(新单色)()_
{New Single(){0,1,1,1,0}_
新的Single(){1,0,1,1,0}_
新的Single(){1,1,0,1,0}_
新的Single(){1,1,1,0}_
新的Single(){0,0,0255,1})
Dim attr作为新的ImageAttributes
将rc标注为新矩形(0,0,输入.宽度,输入.高度)
变暗为新的记忆流
尺寸g作为图形=图形。从图像(输入)
g、 透明(彩色、透明)
attr.SetColorMatrix(trans,System.Drawing.Imaging.ColorMatrixFlag.Default,System.Drawing.Imaging.ColorAdjustType.Bitmap)
g、 DrawImage(tmpImage、rc、0、0、input.Width、input.Height、GraphicsUnit.Pixel、attr)
input.makeTransparent(System.Drawing.Color.White)
保存(输出,ImageFormat.Png)
g、 处置
input.Dispose()
tmpImage.Dispose()
WriteTo(Response.OutputStream)
端接头

非常感谢,这正是我所需要的正确方向。我现在有了一个解决方案,我将在下面发布。非常感谢你,这正是我所需要的正确方向。我现在有一个解决方案,我将在下面发布。