PDA

View Full Version : dotnet greyscale image


Gravey
03-08-2009, 12:24 PM
I've written a small dotnet dll for a client to be used from within max that does some quick and specific image processing based off the bitmapTextures in the scene. It all works perfectly, I'm just stuck on 1 tiny thing. Once processed, I need to save each image as a greyscale tif (8bits per pixel as opposed to 8 bits per channel) and I can't seem to find a way to do this - Maybe i'm not looking hard enough...

ZeBoxx2
03-08-2009, 01:01 PM
are you saving from .NET itself, or copying the bitmap back into max prior to saving?

If the latter, have a peek at the iTifIO interface (or just plain TIF interface). Specifically:

TIF.setType #mono
-- save bitmap to .tif here


If the former - would depend on whatever library is being used to save to .TIF and whether or not that exposes greyscale at all. I know Windows has -some- TIF support to deal with the fax thing, but I'm not sure if that means it's exposed :)

Edit: For .NET: Looks like you'd have to construct a bitmap with the appropriate pixelformat class before saving. However, I'm only seeing a 16bpp grayscale format.
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat.aspx

Gravey
03-08-2009, 01:25 PM
Thanks for the speedy response
I'm saving from .NET
16bpp might be ok. I'm trying it out now and for some reason i'm getting 'dotnet out of memory' errors when i try to use bitmap.clone rect pixelformat.16bppGrayScale method...
i'll try using a graphics object to 'draw' it into a new bitmap instead

EDIT: still getting that out of memory error... seems to be having trouble creating the bitmap for some reason unknown to me

ZeBoxx2
03-08-2009, 01:55 PM
After some Googling about*... it seems like that format is poorly supported, if at all. So back to finding a LIB that supports TIFF saving with parameters (as opposed to having to construct a new bitmap with the given pixel format), methinks :\

* http://objectmix.com/csharp/355108-16bppgrayscale.html

LoneRobot
03-08-2009, 03:05 PM
Thanks for the speedy response
I'm saving from .NET
16bpp might be ok. I'm trying it out now and for some reason i'm getting 'dotnet out of memory' errors when i try to use bitmap.clone rect pixelformat.16bppGrayScale method...
i'll try using a graphics object to 'draw' it into a new bitmap instead

EDIT: still getting that out of memory error... seems to be having trouble creating the bitmap for some reason unknown to me

could be a disposal issue joel, take a look at this article -

http://www.bobpowell.net/imagefileconvert.htm

Gravey
03-09-2009, 02:08 AM
Hey Pete
Thanks for the info, I've tried using Dispose but its still not working. That GDI+ FAQ site may come in handy though. Richard's link about the 16bppgrayscale format not being supported very well seems to have hit the nail on the head unfortunately. I guess i'll have to figure out some crazy work around.

Gravey
03-09-2009, 09:26 AM
ok i have a workaround however it requires the brilliant (and free!) LEAD Tools command line image convertion utility. I was going to be using this anyway because the tif files were to be converted to SGI RGB format (.rgb) and i discovered that it has a switch for bpp. so from max i can just use: HiddenDOSCommand "LFC <sourceDir | sourceFile> <targetDir> /F=FILE_SGI /B8 /NOUI"the /B8 part is the bpp conversion.
You can download LFC from here (http://www.leadtools.com/evaldownload/downloads.aspx?category=Free)

obviously this workaround adds an external dependency but its fine in my case since the client already uses it. Ideally i would have used a dotnet compatible codec for .rgb but i haven't been able to find one and i have no idea where to start to write one.

CGTalk Moderation
03-09-2009, 09:26 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.