1

Is there any simple way to programatically colorize images in .NET? Basically we have a black and white image and need to put a layer of say pink above it and reduce the opacity of that layer to make the picture colorized in pink.

4

5 回答 5

2

You should use the wonderful ImageMagick library. It has .NET bindings so no problem there.

Have fun! :)

于 2008-09-29T09:30:25.233 回答
1

Check out these links:

http://www.codeproject.com/KB/GDI-plus/csharpgraphicfilters11.aspx

http://www.codeproject.com/KB/GDI-plus/KVImageProcess.aspx

于 2008-09-29T09:33:19.437 回答
0

The way that springs to mind is using the Drawing packages to draw a rectangle over the picture in a given colour (you can set alpha). It's not very efficient but, with caching, it wouldn't do any harm, even on a busy server.

于 2008-09-29T09:30:47.960 回答
0

This is a little bit too custom for a .net framework method.. If you can't find a single method call solution.. I post something that could be something to look at.

If you have a WPF, you could load the image in a control. Have another control (Rectangle with Pink fill and Transparency) on top of it. (Use something like a Grid for layout so that both of them overlap perfectly) Next you could

RenderTargetBitmap bmp = new RenderTargetBitmap( imageWidth,imageHeight, 
  DPIHoriz, DPIVert, 
  PixelFormats.Pbrga32);
 // if you don't want to make the controls 'visible' on screen, you need to trigger size calculations explicitly. 
grid.Measure(new Size(imageWidth, imageHeight));
grid.Arrange(new Rect(0,0, imageWidth, imageHeight);
bmp.Render(grid);

So you get whatever you see on screen, written into the Bitmap in memory. You could then save it off. If that doesn't work, you can go for pixel level control with WriteableBitmap class and do byte-labor.

于 2008-09-29T09:45:07.723 回答
0

I think it will be a bit more complicated if you want to colorize an image rather than just putting a smi-transparent layer on top. If you want to have the same effect as the "screen" layer mode in PhotoShop then you have to replace all the shades black in the image with shades of the new color to keep the white parts white.

It can most definetly be done in .NET but I supose it wouldn't hurt to look into a library of some sort.

于 2008-09-29T10:52:04.223 回答