Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am working with GDI+ using its colormap constructor, problem is when GDI pulls in the image to recolor its doing it backwards. The images I pull in are .PNG line art images and the actual line art is black, however when i try to replace the black lines with say, green, my script colors the background not the actual line art! Heres my code:

 

<%@Page Language="vb" debug="true"%>

<%@import NameSpace = "System.Drawing"%>

<%@import NameSpace = "System.Drawing.Graphics"%>

<%@import NameSpace = "System.Drawing.Text"%>

<%@import NameSpace = "System.Drawing.Imaging"%>

<%@import NameSpace = "System.Drawing.Drawing2D"%>

<%

 

Response.Clear()

 

Dim strImgPath as String = "../images/clipart/xero.png"

Dim orgImage As System.Drawing.Image = System.Drawing.Image.FromFile(server.mappath(strImgPath))

Dim swpImage as New Bitmap(orgImage)

Dim g as Graphics = Graphics.FromImage(swpImage)

Dim clrMap(0) As System.Drawing.Imaging.ColorMap

 

 

clrMap(0) = new System.Drawing.Imaging.ColorMap()

clrMap(0).OldColor = color.black

clrMap(0).NewColor = Color.green

Dim attr As ImageAttributes = New ImageAttributes()

attr.SetRemapTable(clrMap)

 

Dim rec as New Rectangle(0,0,swpImage.width, swpImage.height)

g.drawImage(swpImage, rec,0,0,swpImage.Width, swpImage.Height, GraphicsUnit.Pixel, attr)

 

swpImage.Save(Response.OutputStream, ImageFormat.gif)

 

%>

 

The extra namespaces are in there for code that I have to add later. Any help with this would be greatly appreciated.

Posted

Ok, the code above is perfectly clean, the problem that I discovered is that GDI+ understands color.black as the HEX value #000000, is there anyway for me to set it up that GDI would look for all values resembeling the color black? For instance, #242727.

 

Also, is there anyway to set the .newColor dynamically, for instance, connecting to a Database, grabing the appropriate HEX value and input it into the .NewColor?

 

Maybe using ColorTranslator.FromHTML() ?

 

Thanks in advance

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...