Tesseract empty page - c#

I use tesseract for detecting characters on image.
try
{
using (var engine = new TesseractEngine(#"C:\Users\ea\Documents\Visual Studio 2015\Projects\ocrtTest", "eng", EngineMode.Default))
{
using (var img = Pix.LoadFromFile(testImagePath))
{
Bitmap src = (Bitmap)Image.FromFile(testImagePath);
using (var page = engine.Process(img))
{
var text = page.GetHOCRText(1);
File.WriteAllText("test.html", text);
//Console.WriteLine("Text: {0}", text);
//Console.WriteLine("Mean confidence: {0}", page.GetMeanConfidence());
int p = 0;
int l = 0;
int w = 0;
int s = 0;
int counter = 0;
using (var iter = page.GetIterator())
{
iter.Begin();
do
{
do
{
do
{
do
{
do
{
//if (iter.IsAtBeginningOf(PageIteratorLevel.Block))
//{
// logger.Log("New block");
//}
if (iter.IsAtBeginningOf(PageIteratorLevel.Para))
{
p++;//counts paragraph
//logger.Log("New paragraph");
}
if (iter.IsAtBeginningOf(PageIteratorLevel.TextLine))
{
l++;//count lines
//logger.Log("New line");
}
if (iter.IsAtBeginningOf(PageIteratorLevel.Word))
{
w++;//count words
//logger.Log("New word");
}
s++;//count symbols
//logger.Log(iter.GetText(PageIteratorLevel.Symbol));
// get bounding box for symbol
Rect symbolBounds;
if (iter.TryGetBoundingBox(PageIteratorLevel.Symbol, out symbolBounds))
{
Rectangle dueDateRectangle = new Rectangle(symbolBounds.X1, symbolBounds.Y1, symbolBounds.X2 - symbolBounds.X1, symbolBounds.Y2 - symbolBounds.Y1);
rect = dueDateRectangle;
PixelFormat format = src.PixelFormat;
Bitmap cloneBitmap = src.Clone(dueDateRectangle, format);
MemoryStream ms = new MemoryStream();
cloneBitmap.Save(ms, ImageFormat.Png);
ms.Position = 0;
Image i = Image.FromStream(ms);
//i.Save(ms,System.Drawing.Imaging.ImageFormat.Png);
i.Save("character" + counter + ".bmp", ImageFormat.Png);
counter++;
}
} while (iter.Next(PageIteratorLevel.Word, PageIteratorLevel.Symbol));
// DO any word post processing here (e.g. group symbols by word)
} while (iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word));
} while (iter.Next(PageIteratorLevel.Para, PageIteratorLevel.TextLine));
} while (iter.Next(PageIteratorLevel.Block, PageIteratorLevel.Para));
} while (iter.Next(PageIteratorLevel.Block));
}
Console.WriteLine("Pragraphs = " + p);
Console.WriteLine("Lines = " + l);
Console.WriteLine("Words = " + w);
Console.WriteLine("Symbols = " + s);
}
And it works when I have an image with a lot of text, but when I have an image with only one letter it does not.
It found a symbol, I see it in input. Symbols = 1. But it cant get BoundingBox. Why?
The same whem I use alphabet image

You may need to test the OCR with different page segmentation mode and OCR Engine mode to get the best result. Below is the usage information available in Tesseract 4.0.
Page segmentation modes:
0 Orientation and script detection (OSD) only.
1 Automatic page segmentation with OSD.
2 Automatic page segmentation, but no OSD, or OCR.
3 Fully automatic page segmentation, but no OSD. (Default)
4 Assume a single column of text of variable sizes.
5 Assume a single uniform block of vertically aligned text.
6 Assume a single uniform block of text.
7 Treat the image as a single text line.
8 Treat the image as a single word.
9 Treat the image as a single word in a circle.
10 Treat the image as a single character.
11 Sparse text. Find as much text as possible in no particular order.
12 Sparse text with OSD.
13 Raw line. Treat the image as a single text line,
bypassing hacks that are Tesseract-specific.<br>
OCR Engine modes:
0 Original Tesseract only.
1 Neural nets LSTM only.
2 Tesseract + LSTM.
3 Default, based on what is available.
For example,
psm 8 would give the best result for OCR a single word
psm 6 may give the best result of a block of text
In your code, it showed you have used the default engine mode and not specified segmentation mode. You may do some more tests to find out which modes give the correct result.

For images as bellow, use --psm 9 in your tesseract command

Related

Bitmap region locked / bitmap in use elsewhere error

I have a program where I perform OCR on selected text lines in an image, I used a for loop and it works well. Only problem is that in for loop each line is processed after the previous one is done which adds up the processing time.
So I tried using a parallel.for statement so that all lines will be processed together(max 5 lines). When there is only 1 line it works and I get no error, but when there are multiple lines, I get the following errors :
System.InvalidOperationException: 'Bitmap region is already locked.'
OR Bitmap is in use elsewhere
Im using EMGU and tesseract class for processing.
This is my code :
private void ocrmethod()
{
this.Invoke((MethodInvoker)delegate
{
Image<Gray, byte> temp = frame.Convert<Gray, byte>().Clone();
// for (int i = 0; i < imgcount; i++)
Parallel.For(0, imgcount, i =>
{
temp.ROI = LineRect[i]; // Selected text line region in the image
OCR_Class doocr = new OCR_Class();
Image<Gray, byte> foundareafilter = temp.Copy();
bitmap2 = new Bitmap(foundareafilter.ToBitmap<Gray, byte>());
//OCR SECTION
doocr.trainingdatapath(#"./OCRtraindata", "eng");
doocr.ProcessOCR(bitmap2, 1);
string result = doocr.result().Replace(" ", "").Replace(" ", "");
// }
});
});
}
I cant figure out how to make the bitmaps available to all process simultaneously. Please help.
Changing external variables in a parallel loop leads to their locking.
bitmap2 = new Bitmap(foundareafilter.ToBitmap<Gray, byte>());
You need to make thread-safe code
Patterns for Parallel Programming: Understanding and Applying
Parallel Patterns with the .NET Framework 4 - Stephen Toub

How to set ReadBarcodes properly

I am trying to read a 3of9 barcode.
3of9 barcode Image
the result that is giving me is inconstant but the location is still the same. (tried running that method multiple times same Image/barcode and same position)
What I mean by inconstant is sometimes I am getting the value of the barcode
ex.
barcodesd.Length is not zero so it is getting the barcodesd[0].Value which is
25350111
and sometimes the barcodesd.Length = 0
here is my code:
public static string DecodeImg(System.Drawing.Bitmap img)
{
System.IO.MemoryStream data = new MemoryStream();
RasterImage srcImage = null;
try
{
BarcodeEngine engine = new BarcodeEngine();
Leadtools.Codecs.RasterCodecs codecs = new Leadtools.Codecs.RasterCodecs();
img.Save(data, System.Drawing.Imaging.ImageFormat.Jpeg);
data.Seek(0, System.IO.SeekOrigin.Begin);
srcImage = codecs.Load(data);
BarcodeData[] barcodesd = engine.Reader.ReadBarcodes(srcImage, LeadRect.Empty, 0, BarcodeEngine.GetSupportedSymbologies(), null);
srcImage.Dispose();
if (barcodesd != null)
{
if (barcodesd.Length > 0)
return barcodesd[0].Value;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
data.Dispose();
if (srcImage != null)
srcImage.Dispose();
}
return "Unable to Read";
}
The barcode in the image is not properly encoded. It appears whoever (or whatever) generated it tried to insert 2 asterisk "*" characters inside it.
The "*" character is not a true encodable character, but is the start and stop symbol for Code 3 of 9 barcodes. This means it should not be inserted inside the barcode string.
Since there are 2 such "*" characters inside the code, a reader might be able to "find" the middle portion and consider it a valid barcode on its own. But that is not predictable since the encoding of the entire code is incorrect.
If you believe the code is valid, and you have evidence to that from any source (for example, a different barcode reader can consistently recognize it), please send the images you have to support#leadtools.com and provide full details about your findings. Also include information about which version of the SDK and which platform you’re using (for example v20, 64-bit C# WinForms).

ItextSharp font color issue in ver 5.5.4+

I have some code that creates a red "stamp" using a red font color:
string StampDate = DateTime.Now.ToString("MM/dd/yyyy");
string FontPath = Server.MapPath("/assets/Fonts");
string OrigFile = Server.MapPath("/test.pdf");
const int OpacityPercent = 80;
const float PDFPaidFontSize = 28;
const float PDFCopyX = 170;
const float PDFPaidX = 385;
const float PDFY = 20;
const float PDFDateXOffset = 7;
const float PDFDateYOffset = 12;
const float PDFDateFontSize = 10;
const string PaidStampTxt = "PAID";
const string CopyStampTxt = "COPY";
const string ArialFilename = "arialbd.ttf";
PdfStamper stamper = null;
PdfReader reader = null;
PdfReader.unethicalreading = true;
MemoryStream streamPDF;
try
{
reader = new PdfReader(OrigFile);
streamPDF = new MemoryStream();
stamper = new PdfStamper(reader, streamPDF);
for (int i = 1; i <= reader.NumberOfPages; i++)
{
PdfGState gstate = new PdfGState();
gstate.FillOpacity = gstate.StrokeOpacity = OpacityPercent / 100F;
PdfContentByte overContent = stamper.GetOverContent(i);
overContent.SaveState();
overContent.SetGState(gstate);
overContent.SetColorFill(BaseColor.RED);
overContent.BeginText();
BaseFont font = BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
overContent.SetFontAndSize(font, PDFPaidFontSize);
overContent.ShowTextAligned(PdfContentByte.ALIGN_LEFT, CopyStampTxt, PDFCopyX, PDFY, 0);
overContent.ShowTextAligned(PdfContentByte.ALIGN_LEFT, PaidStampTxt, PDFPaidX, PDFY, 0);
overContent.SetColorFill(BaseColor.BLACK);
font = BaseFont.CreateFont(Path.Combine(FontPath, ArialFilename), BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
overContent.SetFontAndSize(font, PDFDateFontSize);
overContent.ShowTextAligned(PdfContentByte.ALIGN_LEFT, StampDate, PDFPaidX + PDFDateXOffset, PDFY - PDFDateYOffset, 0);
overContent.EndText();
overContent.RestoreState();
}
}
finally
{
if (stamper != null)
{
stamper.Close();
}
if (reader != null)
{
reader.Close();
}
}
byte[] pdf = streamPDF.ToArray();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Buffer = false;
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.Charset = string.Empty;
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", pdf.Length.ToString());
Response.AddHeader("Content-Disposition", "inline;filename=test.pdf;");
Response.BinaryWrite(pdf);
Response.Close();
The resulting pdf text has a gray color instead of red.
When i reverted back to ver 5.5.3 it shows up as red again. I have tried 5.5.4 and 5.5.5 and they both appear to have the same issue.
My question is: Is this a bug or do I need to change my code to something newer?
Edit: This appears to only be an issue with certain pdf files. Changing the fonts and pdf file versions did not seem to have an effect.
Comparing a pdf that does work and a pdf that does not work (neither i can share publicly) I noticed that the pdf that does NOT work is a tagged pdf, has fast web view enabled, and was produced by adobe pdf library. A pdf that DOES work is NOT a tagged pdf, does NOT have fast web view enabled, and was created by itextsharp.
Since I cannot control what the source pdf files will be, I reverted to an earlier version of itextsharp that seems to work all the time.
A first attempt to reproduce the issue
I just executed your code for these values:
int OpacityPercent = 70;
int PDFPaidFontSize = 20;
string CopyStampTxt = "COPY";
string PaidStampTxt = "PAID";
int PDFCopyX = 100;
int PDFPaidX = 250;
int PDFY = 500;
string FontPath = #"C:\Windows\Fonts";
string ArialFilename = "ariali.ttf";
int PDFDateFontSize = 30;
string StampDate = "TODAY";
int PDFDateXOffset = 0;
int PDFDateYOffset = 35;
with a simple source PDF, and the result PDF looks like this:
In contrast to your observation
The resulting pdf text has a gray color instead of red.
the resulting text color is reddish (a partially transparent red on white).
I tested using iTextSharp 5.5.5.
To get a gray color instead of red, therefore, there must be something special about your variable values or source PDF, it is not a general iTextSharp issue.
Reproducing the issue using the file provided by the OP
After the first attempt to reproduce the issue, the OP provided a sample file Test.pdf, and indeed, for this file the result of the same code is:
Thus, there indeed is an issue.
Analysis
A comparison of the added content stream operations in both cases shows:
For the first attempt using my sample PDF:
/Xi0 gs
1 0 0 rg
BT
/Xi1 20 Tf
1 0 0 1 100 500 Tm
(COPY) Tj
for the second attempt using the OP's sample file:
/Xi0 gs
1 0 0 rg
BT
0 g
/Xi1 20 Tf
1 0 0 1 100 500 Tm
(COPY) Tj
Thus, in spite of the same code been used, there is an additional 0 g operation in the latter case, and that operations selects black as fill color.
This came as quite a surprise. Thus, I looked through the iText code and code history for an explanation (I chose the iText/Java code as that's where the original development takes place and changes can be inspected more thoroughly).
And indeed, PdfContentByte.beginText ends with:
if (isTagged()) {
try {
restoreColor();
} catch (IOException ioe) {
}
}
Backgrounds
Thus, in case of tagged PDFs this method "resets the color". Why that?
Looking through the code history gives some hints
Revision 5499 Tagged PDF support: keeping graphics and text in one canvas. Not yet ready...
Revision 5515 Now iText can write both text and graphics into 1 canvas. For that you should set PdfDocument.putTextAndGraphicsTogether to true.
Here the block above first appears with a slight difference
if (autoControlTextBlocks) {
try {
restoreColor();
} catch (IOException ioe) {
}
}
i.e. here the color is restored only if autoControlTextBlocks is true.
...
Revision 5533 writer.isTagged property now decides whether to write all content in one canvas or into separate ones.
Here the flag autoControlTextBlocks is replaced by a isTagged call of the associated writer.
My interpretation:
To properly support tagged PDFs, it was necessary or at least advantageous to keep graphics and text in one canvas (formerly they were created in different canvasses which eventually were concatenated, so related graphics and texts were distant from each other in the content).
To keep graphics and text together with minimal overhead in the highlevel code, a new autoControlTextBlocks mode has been added to PdfContentByte which starts and stops text objects automatically where needed and saves and restores a separate color set for texts.
This mode seems to have been chosen as means for support of tagged content in iText while it seems to not have been considered useful for other contexts. Thus, this mode now automatically is used for tagged files.
In my opinion this choice is not optimal. PdfContentByte is part of the publicly available iText API and it is publicly advertised (as "over content") for low-level tweaking of generated or pre-existing PDFs. Introducing such side-effects violates the API contract, at least it is a nuisance keeping people from upgrading.
Work-around
Simply switch the order of the color setting and text object starting operations, using
...
overContent.BeginText();
overContent.SetColorFill(BaseColor.RED);
...
results in
Resolution
If I interpret the final check-ins correctly, this issue should be fixed in iText version 5.5.6.
commit 301a45b57dcef37ae0ec3625fbdd6caaf4004a3a
Removed deprecated logic of saving and restoring color for tagged pdf documents in PdfContentByte class (DEV-1371).

Print Unicode Characters to POS printer

I'm trying to print my language characters to a POS printer. The Printer prints well but the result's so bad. This is what I tried:
using (MemoryStream ms = new MemoryStream())
using (BinaryWriter bw = new BinaryWriter(ms))
{
bw.Write(AsciiControlChars.Escape);
bw.Write('#');
//ESCCMD.RenderBitmap(bw, logo);
bw.Write("Đây là Tiếng Việt");
bw.Write(AsciiControlChars.Escape);
bw.Write('d');
bw.Write((byte)3);
// Feed 3 vertical motion units and cut the paper with a 1 point uncut
bw.Write(AsciiControlChars.GroupSeparator);
bw.Write(AsciiControlChars.V);
bw.Write((byte)66);
bw.Write((byte)3);
bw.Flush();
RawPrinterHelper.SendToSerialPort(ms.ToArray(), txtPortTest.Text, Convert.ToInt32(cbbBaudRate.SelectedValue));
}
So how can I print my language characters using ESC/POS command?
Thanks so much!
Before printing international characters you need to check if your specific model supports the corresponding codepage and then set it with the ESC t command. The list of supported code pages for EPSON printers and the command syntax info is available here: https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=32 (registration required)
For example, in order to print Greek (ISO-8859-7) text, you need to do something like this:
private void PrintGreekIsoText(BinaryWriter bw, string text)
{
// ESC t 15
bw.Write("\x1bt\x15");
// Convert the text to the appropriate encoding
var isoEncoding = Encoding.GetEncoding(28597);
var bytes = Encoding.Unicode.GetBytes(text);
byte[] output = Encoding.Convert(Encoding.Unicode, isoEncoding, bytes);
bw.Write(output);
}

How can I delete tiff tags using the LibTiff.Net 2.3 library

I can't seem to find any documentation of how to delete a tiff tag using the LibTiff.Net library. I love the library but this one method is important to what I need to do. At one point I was hoping that I could just set a tag and set it's value to nothing. I had hoped that would work but that was a negative.
Anyone know how to delete a tiff tag using the LibTiff.Net library?
Please have a look at TiffCP utility (and especially its source code) shipped with LibTiff.Net.
LibTiff.Net doesn't offer methods for removing tags (the same is true for LibTiff). You will need to implement part of TiffCP functionality in order to achieve that.
Basically, you will need to copy all tags you wish to retain, and copy pixels data without decoding and re-encoding it.
Please also have a look at Convert a multi-strip TIFF image to a single-strip one sample. It shows how to copy tags and copy raw (undecoded data) from one image to another. The sample actually decodes data in some cases because it needs to change number of strips, but you won't need to decode data.
I think you will have to basically copy the input file to a new TIFF image filtering out the tags you don't want in the process. Take a look at the tiffcp utility which is part of the regular libtiff distribution. It sort of does that, minus filtering.
Disclaimer: I've never used LibTiff.Net and am assuming that it is very similar to the LibTiff.
Take a look at tiffcp.c
First it manually copies/sets some known tags such as resolution, compression, colors etc.
Then it copies all a set of tags that can be copied w/o preprocessing:
for (p = tags; p < &tags[NTAGS]; p++)
CopyTag(p->tag, p->count, p->type);
Then it copies the actual pixel data. This will from what I recollect, drop any tags that are not known to tiffcp. If your tag that you want to drop is in the list, you can trivially drop it by removing it from that list.
Note: As first this might look like a big answer but I wanted to make sure that whoever was looking at this see's all the "proprietary classes I have created to keep everything boxed up for cleanness. In the interest of keeping the answer as sort as possible and to be informative I will only paste the code for the DeleteTiffTags method. The rest of the code can be downloaded via here.
Now on to the good stuff... I ended up spending about a day on making this happen and it was possible thanks to various questions being answered by the great stackoverflow community. I wrote two little (very detailed) method in one of my classes to delete a tiff tag. The first one is meant to delete a list of given tags and the second one is to delete a single tag which works off the for mentioned method. Also in this example I added a few lines to support my custom tiff tags... They will all be preceded with the //ADDED comment.
Classes:
public static class TIFFTAGS
- This class is the main class that is simply called by doing something like TIFFTAGS.DeleteTiffTags(); Since it's a static class
there is no need to create an object of it to use it's methods.
private class TIFFTAGS_PAGE
- This class is a private class that resides inside the TIFFTAGS class. It's purpose is to contain all the single page info for all
the pages that might be in the tiff. It is private and only used for
internal purposes.
public class TIFFTAGS_TAG
- This is a class I made to wrap up the tags in something more to my liking. Using the standard tag type names such as ASCII, SHORT, LONG,
and RATIONAL.
Methods/Functions:
TagExtender()
- This little gem is a callback function that allows you to actually keep your CUSTOM tags in the tiff. Without it ALL of your custom tags
would disappear when you deleted any tag (even if you deleted just
one).
DeleteTiffTags()
- This is the main method that deletes a list of tags. Simply pass in a list of ushort tag numbers and all will be deleted. Keep in mind
not using the TagExtender function will cause your custom tags to go
poof!
DeleteTiffTag()
- This is simply used to delete a single tiff tag. It calls upon DeleteTiffTags() to handle the grunt work.
public static bool DeleteTiffTags(string sFileName, List<ushort> ushortTagNumbers)
{
//Deletes a list of tiff tag from the given image
//Returns true if successful or false if error occured
//Define variables
List<TIFFTAGS_PAGE> ttPage = new List<TIFFTAGS_PAGE>();
//Check for empty list
if (ushortTagNumbers.Count == 0) return false;
try
{
//ADDED
m_lTagsToWrite = new List<TIFFTAGS_TAG>();
m_lTagsToWrite.Add(new TIFFTAGS_TAG("", 38001, Convert.ToString("")));
m_lTagsToWrite.Add(new TIFFTAGS_TAG("", 38002, Convert.ToString("")));
m_parentExtender = Tiff.SetTagExtender(TagExtender);
//Open the file for reading
using (Tiff input = Tiff.Open(sFileName, "r"))
{
if (input == null) return false;
//Get page count
int numberOfDirectories = input.NumberOfDirectories();
//Go through all the pages
for (short i = 0; i < numberOfDirectories; ++i)
{
//Set the page
input.SetDirectory(i);
//Create a new tags dictionary to store all my tags
Dictionary<ushort, FieldValue[]> dTags = new Dictionary<ushort, FieldValue[]>();
//Get all the tags for the page
for (ushort t = ushort.MinValue; t < ushort.MaxValue; ++t)
{
TiffTag tag = (TiffTag)t;
FieldValue[] tagValue = input.GetField(tag);
if (tagValue != null)
{
dTags.Add(t, tagValue);
}
}
//Check if the page is encoded
bool encoded = false;
FieldValue[] compressionTagValue = input.GetField(TiffTag.COMPRESSION);
if (compressionTagValue != null)
encoded = (compressionTagValue[0].ToInt() != (int)Compression.NONE);
//Create a new byte array to store all my image data
int numberOfStrips = input.NumberOfStrips();
byte[] byteImageData = new byte[numberOfStrips * input.StripSize()];
int offset = 0;
//Get all the image data for the page
for (int n = 0; n < numberOfStrips; ++n)
{
int bytesRead;
if (encoded)
bytesRead = input.ReadEncodedStrip(n, byteImageData, offset, byteImageData.Length - offset);
else
bytesRead = input.ReadRawStrip(n, byteImageData, offset, byteImageData.Length - offset);
//Add to the offset keeping up with where we are
offset += bytesRead;
}
//Save all the tags, image data, and height, etc for the page
TIFFTAGS_PAGE tiffPage = new TIFFTAGS_PAGE();
tiffPage.Height = input.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
tiffPage.Tags = dTags;
tiffPage.PageData = byteImageData;
tiffPage.Encoded = encoded;
tiffPage.StripSize = input.StripSize();
tiffPage.StripOffset = input.GetField(TiffTag.STRIPOFFSETS)[0].ToIntArray()[0];
ttPage.Add(tiffPage);
}
}
//Open the file for writing
using (Tiff output = Tiff.Open(sFileName + "-new.tif", "w"))
{
if (output == null) return false;
//Go through all the pages
for (short i = 0; i < ttPage.Count(); ++i)
{
//Write all the tags for the page
foreach (KeyValuePair<ushort, FieldValue[]> tagValue in ttPage[i].Tags)
{
//Write all the tags except the one's needing to be deleted
if (!ushortTagNumbers.Contains(tagValue.Key))
{
TiffTag tag = (TiffTag)tagValue.Key;
output.GetTagMethods().SetField(output, tag, tagValue.Value);
}
}
//Set the height for the page
output.SetField(TiffTag.ROWSPERSTRIP, ttPage[i].Height);
//Set the offset for the page
output.SetField(TiffTag.STRIPOFFSETS, ttPage[i].StripOffset);
//Save page data along with tags
output.CheckpointDirectory();
//Write each strip one at a time using the same orginal strip size
int numberOfStrips = ttPage[i].PageData.Length / ttPage[i].StripSize;
int offset = 0;
for (int n = 0; n < numberOfStrips; ++n)
{
//Write all the image data (strips) for the page
if (ttPage[i].Encoded)
//output.WriteEncodedStrip(n, byteStrip, offset, byteStrip.Length - offset);
output.WriteEncodedStrip(0, ttPage[i].PageData, offset, ttPage[i].StripSize - offset);
else
output.WriteRawStrip(n, ttPage[i].PageData, offset, ttPage[i].StripSize - offset);
//Add to the offset keeping up with where we are
offset += ttPage[i].StripOffset;
}
//Save the image page
output.WriteDirectory();
}
}
//ADDED
Tiff.SetTagExtender(m_parentExtender);
}
catch
{
//ADDED
Tiff.SetTagExtender(m_parentExtender);
//Error occured
return false;
}
//Return success
return true;
}

Categories

Resources