TIFF file highlight area C# example?

J

JimB

I need some .NET sample code that allows me to load a TIFF file via
System.Drawing.Bitmap bitmap or TiffBitmapDecoder decoder = new
TiffBitmapDecoder. I'm lost trying to tie all the pieces together. I
know I need to convert the tiff into a bitmap so I can use setpixel
correct? The method will pass in the x,y coord. of the area of the
TIFF file and a color to change it to. My TIFFs are black and white
so I was told I need to convert it to grayscale in order to change the
pixel color to light green for example. Basically I want to change
all the white pixels to a light green color in one specific area of
the image.

Can someone show me a sample code snippet that would accomplish this
using .NET C#, my project is a wpf application.

thanks!
 
P

Peter Duniho

I need some .NET sample code that allows me to load a TIFF file via
System.Drawing.Bitmap bitmap or TiffBitmapDecoder decoder = new
TiffBitmapDecoder.

The Image.FromFile() method should work fine.
I'm lost trying to tie all the pieces together. I
know I need to convert the tiff into a bitmap so I can use setpixel
correct?

You can use the Bitmap.SetPixel() method, but it's pretty much the least
efficient way to modify an image. If all you need to do is actually set
one single pixel, it's the way to go. But otherwise, you should be
looking at the Graphics class.
The method will pass in the x,y coord. of the area of the
TIFF file and a color to change it to.

For coloring an area of an Image instance, see Graphics.FromImage() and
Graphics.FillRect().
My TIFFs are black and white
so I was told I need to convert it to grayscale in order to change the
pixel color to light green for example.

The bitmap format will have to support the image results you are looking
for. If you want to see color, grayscale isn't going to be sufficient.
Basically I want to change
all the white pixels to a light green color in one specific area of
the image.

That's somewhat harder, because your color depends not just on the
specific area and the new color, but on what exists there already. As far
as I recall, the basic .NET drawing API (e.g. System.Drawing.Bitmap, etc.)
doesn't provide support for that kind of operation in the API. You're
basically asking to do a colorkey drawing onto the image.

You can accomplish it explicitly using GetPixel() and SetPixel(), but that
will be incredibly slow. A better approach is to process the image data
directly, using the Bitmap.LockBits() method to get that data, and then
your own code to deal with it. Alternatively, you may be able to use the
colorkey support that's in DirectDraw/Direct3D/XNA (but I'm much less
familiar with those technologies as they relate to .NET, so I can't be of
much help there).
Can someone show me a sample code snippet that would accomplish this
using .NET C#, my project is a wpf application.

WPF should have more to do with the presentation of the results, than of
the manipulation of the images themselves. As far as sample code goes, if
you look at the documentation for the various classes and methods I
mentioned above, you should find a number of code examples, along with
descriptions of how to use those classes and methods.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top