 |
|
 |
Getting the data from the tags of a TIFF image I'm trying to make a program in C# that opens a TIFF image and puts the data from the tags in texboxs but I do not know how to extract the data. If anyone knows how can help me. thanks
modified on Tuesday, August 11, 2009 9:06 AM
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
I needed something to insert a line of text (electronic audit trail) on images that come through. The documents are bi-tonal TIFFs coming in, but I was having a difficult time trying to write onto the image and then save the bi-tonal TIFF out.
Thanks!
Lauren
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
Hello, In your line of code: source = new Bitmap(original.Width, original.Height, PixelFormat.Format32bppArgb);
It saves the image as 96dpi regardless of the actual dpi of the image, resulting in image viewers/libraries rendering it incorrectly. If you add:
source.SetResolution(original.HorizontalResolution, original.VerticalResolution);
immediately afterwards, all is well, i.e. when saving a 200dpi image, it used to class it as 96dpi, when with the code above it saves it as 200dpi.
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
|
 |
|
 |
1. Code below draws any bitmap correctly, including 1bpp bitmap:
Graphics g = pictBox.CreateGraphics(); Bitmap bitmap = new Bitmap("..."); e.Graphics.DrawImage(bitmap); 2. To edit 1bpp bitmap, create new 1bpp Bitmap with the same size, select black pixels by using BitmapData.Scan0 and pointers, and apply new bitmap by using AND operator to the first bitmap. Then, Bitmap.Save() works fine.
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
Dear sir, thanks for the great code! I have been merging multiple tiff images in to one with this code. But when I try to print the result document of say 5 mb, it takes 150mb in the spooler. what to do?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I'm glad you are finding the code useful. I'm afraid I can't be of much help with the printing. I suspect that when the image is sent to the print spooler, it is getting uncompressed to the full resolution of the printer, perhaps as an RGB image. A 600 dpi RGB image, at an 8.5" x 11" size will take up a lot of memory.
For example:
((8.5" x 600dpi) x (11" x 600dpi)) * 3 bytes per pixel = 100,980,000 bytes (or about 100 meg)
One possible solution that comes to mind is seeing if you can drop down the printer resolution to 300 dpi if you don't need to print at a high resolution.
Another solution might be to reduce the size of the bitmap itself if you don't need a high resolution.
I'm not sure which problem is affecting you, these are just my thoughts and hopefully useful advice.
Best Regards, Michael McCLoskey
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Dear Michael McCLoskey Sir, Thanks for the information. The origional files are with 200dpi and the new file comes with 96dpi, but the size is almost 12 times the original files total size. And still facing the same problem with printing. The print spool size goies to 152mb. Thanks,
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
I have placed simple a C# 2005 command-line project on my website. It's an easy way to fax dynamic reports.
Link to the blog page.
If you have FaxComEx.dll, you can simply provide the URL, FAX number and FAX Server name.
If you don't, you can provide a URL, and stdout will provide the generated TIFF name.
I do some basic random dithering that doesn't eat up too many cycles - good enough for my project!
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Very cool stuff! I'm very happy to see my code put to good use. Thanks for the credit. I might have call to use that dithering code you added at some point. I hope you don't mind.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
When I use Bitonal code output image resolution is 120 X 120 dpi instead of 300 x 300 dpi and also size of image is 27.50" and 21.33" instead of 11.00" x 8.5". Please advice me what change I need in code to get mention result. Thanks for nice code.
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
The Bitmap class has a SetResolution method that can be used to configure the resolution. You could try calling that with (300,300) immediately before saving the image to set the correct resolution. I think the code tries to maintain the resolution of the source image. Are you sure the source image is a 300 dpi image? Either way, calling SetResolution prior to saving the image should do trick.
You're welcome for the code. I'm glad you can use it.
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
Thank you very very much for your help to correct size & resolution. I add one line before saving image like., bitonalBitmap.SetResolution(300, 300) and it works great ,it save new image with 8.5" x 11.0" & 300 x 300 dpi. Actually I don't know C# so I convert code from C# to VB2005. Thanks again.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
This works great for me with one page documents, but it appears to cut off multiple page TIFF documents to just the first page. Am I doing something wrong or is this not supported?
Thanks
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
I didn't really consider multipage TIFF documents when writing this article, but I believe the technique should be adaptable to working with them. I'd recommend opening the source TIFF, iterating each page and making any necessary changes to each page, and then saving the results to a new destination TIFF.
To save a multipage TIFF, you have to do something like this for the first page:
Encoder encoder = Encoder.SaveFlag; EncoderParameters encoderParameters = new EncoderParameters(1); EncoderParameter encoderParameter = new EncoderParameter(encoder,(long)EncoderValue.MultiFrame); encoderParameters.Param[0] = encoderParameter; currentImage.Save(filename, imageCodecInfo, encoderParameters);
And then do a SaveAdd for subsequent pages, saving each additional bitmap to the file:
encoderParameter = new EncoderParameter(encoder,(long)EncoderValue.FrameDimensionPage); encoderParameters.Param[0] = encoderParameter; currentImage.SaveAdd(additionalImage, encoderParameters);
When you're all done writing pages, you close the multipage TIFF like this:
encoderParameter = new EncoderParameter(encoder, (long)EncoderValue.Flush); encoderParameters.Param[0] = encoderParameter; currentImage.SaveAdd(encoderParameters);
To determine the number of pages in the source TIFF you use GetFrameCount with a parameter of FrameDimension.Page:
pageCount = bitmap.GetFrameCount(FrameDimension.Page);
To set the active page in the source TIFF you use SelectActiveFrame thusly:
bitmap.SelectActiveFrame(FrameDimension.Page, pageIndex);
This guy has some good tips and code for working with multipage TIFF's
http://www.bobpowell.net/
I hope this helps you out in some way.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
the code works excellent and very fast on files up to a certain image size, after that memory/buffer problems start to show up, I tested on a 36x48" 200 dpi TIF, that is 9600x7200 pixels (I have to work with engineering drawings, and not letter size sheets) - that size just makes it into reasonable buffer size and processes fine in ~10 secs. at 400dpi - 36x48" (thats 14400x19200 pixels) the required buffer image size gets so large the byte array fails to initialize, also the graphics, draw image unscaled method fails with out of memory. The display of these files fails as well, which I dont really care much about, howevere it would be nice to optimize this code so at least the operation can be done in memory - no display required, here is my suggestions; I hope the author or someone else can optimize the code for this -check the image size and process the image in chunks, rather then all at once, ( or use multiple buffers if memory permits ) - use bitblt or iterate through the bitmap to draw the original bitmap onto the rgb converted version, because the drawunscaled method inside converttorgb fails with large images
any better tips, lets hear them ? thanks in advance
|
| Sign In·View Thread·PermaLink | 1.67/5 |
|
|
|
 |
|
 |
I've been wracking my brain on ways to deal with the issue you mention and think it might be possible to come up with a solution, but it would not be trivial to implement. Assuming you can load the 14400 x 19200 image bitonal image successfully, it should be possible to operate on it in parts. The technique would require writing two additional methods. One method would create an editable, 32 bit RGB bitmap from a portion of the larger image and a separate method would replace that portion of the bitonal image with the modified 32 bit RGB bitmap. Assuming you were not modifying a large section of the image at one time, this should work. If you need to have an editable 32 bit version of the entire image at one time to modify, then I don't know of any alternatives to having enough RAM available to accommodate the huge bitmap (something like 1.1 Gig of RAM in this case).
Would this type of solution work for what you are trying to do?
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
thanks for the response, I have worked around my problem successfully, (using the techniques in your article) ultimately what I was after was reading 2 bitonal tif files into memory and creating a third file, this time in colour that has colour pixels set based on the identical or different pixels of the bitonal tif's - and do this all in a reasonable amount of time for a 14400x19200 sized file (if you attempt to use the .net getpixel/setpixel methods you are in for a long wait - it takes forever) - well the memory footprint of a 32bit RGB bitmap is brutal, I didnt need aRGB colour scheme anyways so instead of creating a 32bit GDI+ bitmap I have created an 8bit indexed TIF in a byte array and modified the pixels directly in the byte array (this gives a max of 256 possible colours - choosen from a palette of 24bit) - plenty for what I needed to do. The code after a bit of profiling allows me to compare 2 TIF files in under 10 secs and creates a colour output file at high quality. I still would like to find a way to buffer a 24bit or 32bit image in parts in memory and be able to work with it, just curiousity and for possible future projects - it certainly is a challenging task
|
| Sign In·View Thread·PermaLink | 3.00/5 |
|
|
|
 |
|
 |
Dear Cinamon!
I'am sitting at home and trying to do some similar job. My TIFF is a 1pbb Tiff with 50400 x 63157 pixel size. The data i want to integrated into this file are represented within another tiff file, also 1pbb Tiff with 50400 x 63157 pixel size.
In fact i want to load both files and write the "black" pixels of both into a new file. It sounds that you did such a job succesfully - can you please provide me with some further details of your code pimps, so that i can go on with it.
thx a lot in advance Oliver
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Are you able to even load one of these big boys into a .NET bitmap object? If my calculations are correct, then each of these images will eat up about 380 meg of memory. To do a merge on them would require at least twice that amount of memory. If you can load one of them into memory and have a couple gigs of memory on the machine, then it might be feasible and I could probably offer up some code to make it happen. In this case though, you wouldn't want to convert them to any sort of color representation because that would definitely bring any computer to its knees. You'd want to load each source image into memory and create a method that locks blocks of the image data in each image, gets the data into byte arrays and OR's the data together, then writes the data back out into one of the images.
A different approach might be to try to manipulate the image bytes on disk. If you were able to save the images as uncompressed TIFF's, then the image bytes in the files should be laid out linearly and combining two images of the same size should just be a matter of walking the bytes and OR'ing the image data together. You'd have to be able determine the offset into the TIFF files where the actual image data resides so you don't overwrite the header or any non-image data in the files. This method might be tricky, but it would definitely be more memory friendly and might actually be faster than the first method.
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
Hi,
I'm trying to load a tif image using Image.FromFile and I am getting an out of memory exception.
An unhandled exception of type 'System.OutOfMemoryException' occurred in system.drawing.dll
Additional information: Out of memory.
I tried loading it using a stream, and I am getting an Invalid parameter exception.
I need to somehow convert thi tif image to a valid jpeg or jpg format.
Has anyone faced this issue before? Can I get some code to solve this problem?
I will be unable to use any libraries that 3rd parties are providing and will have to write my own code.
Thanks in advance.
|
| Sign In·View Thread·PermaLink | 1.50/5 |
|
|
|
 |
|
 |
There are limits on the size of a bitmap that may be loaded in memory. While some third party products support loading and operating on parts of an image, the .NET framework methods only support loading the entire image into memory. If you are working with large images, particularly color images, then you need to make sure your system can handle it. You can get a rough idea of the memory required to load an image by multiplying the width in pixels by the height in pixels and multiplying the result by one of the following factors to determine the bytes of memory required to load the image:
For 32 bit images -> Memory in bytes = width * height * 4 For 24 bit images -> Memory in bytes = width * height * 3 For 16 bit images -> Memory in bytes = width * height * 2 For 8 bit (256 color/grayscale images) -> Memory in bytes = width * height * 1 For 1 bit (Black and White) images -> Memory in bytes = width * height * 0.125
It seems like you are trying to load an image too large for the available memory in your system. Out of memory conditions can also occur if you are performing multiple operations with bitmaps and don't call Dispose on each bitmap object when you are done with it, so please be mindful of that too. I've had that cause me problems on multiple occasions.
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
If I have the 'Out of memory' exception and I want to minimize the possibility of it to happen, what should I do:
a) Add more RAM? b) Adjust my virtual memory settings? c) Anything other than above?
Thanks.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |