Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8834713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:05:16+00:00 2026-06-14T09:05:16+00:00

I’m observing mirroring effect when I process image that comes from a scanner through

  • 0

I’m observing “mirroring” effect when I process image that comes from a scanner through libtiff.net.

Here is my code:

public static byte[] GetTiffImageBytes(byte[] win32Bitmap, WinApi.BITMAPINFOHEADER infoHeader)
{
    try
    {
        using (var ms = new MemoryStream())
        {
            using (Tiff tif = Tiff.ClientOpen("InMemory", "w", ms, new TiffStream()))
            {
                if (tif == null)
                    return null;

                tif.SetField(TiffTag.IMAGEWIDTH, infoHeader.biWidth);
                tif.SetField(TiffTag.IMAGELENGTH, infoHeader.biHeight);
                tif.SetField(TiffTag.COMPRESSION, Compression.CCITTFAX4);
                tif.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK);
                tif.SetField(TiffTag.ROWSPERSTRIP, infoHeader.biHeight);

                // TODO: ? Used to be resolutions?
                tif.SetField(TiffTag.XRESOLUTION, infoHeader.biWidth);
                tif.SetField(TiffTag.YRESOLUTION, infoHeader.biHeight);

                tif.SetField(TiffTag.SUBFILETYPE, 0);
                tif.SetField(TiffTag.BITSPERSAMPLE, 1);
                tif.SetField(TiffTag.FILLORDER, FillOrder.MSB2LSB);
                tif.SetField(TiffTag.ORIENTATION, Orientation.TOPLEFT);

                tif.SetField(TiffTag.SAMPLESPERPIXEL, 1);
                tif.SetField(TiffTag.T6OPTIONS, 0);
                tif.SetField(TiffTag.RESOLUTIONUNIT, ResUnit.INCH);

                tif.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);

                // Image "stride" is a lenght in bytes of one pixel row
                var stride = infoHeader.biSizeImage / infoHeader.biHeight;
                var offset = infoHeader.biSize;

                // raster stride MAY be bigger than TIFF stride (due to padding in raster bits)
                for (int i = 0; i < infoHeader.biHeight; i++)
                {
                    var res = tif.WriteScanline(win32Bitmap, offset, i, 1);
                    if (!res) return null;

                    offset += stride;
                }
            }

            return ms.GetBuffer();
        }
    }
    catch (Exception ex)
    {
        return null;
    }
}

I adapted this code from following sample: http://bitmiracle.com/libtiff/help/convert-system.drawing.bitmap-to-a-black-and-white-tiff.aspx

win32 bitmap that passed in have header (also duplicated as parameter).
Basically, I copy rows of data into TIFF and I do get image but it is mirrored and looks like this:
I am very new to win32 code (this bitmap is from twain driver) and not sure if it’s OS related.

I call win32 via P-Invoke from Silvrlight and I get bitmap back and process inside Silverlight’s version of LibTiff.net. I think I need to “mirror” scan lines when I add them to TIFF but I wonder if I need to re-invent wheel or it’s already somehow included in a library?

See how image comes up when I process it using code above:

enter image description here

EDIT

Changed following line:

tif.SetField(TiffTag.ORIENTATION, Orientation.TOPLEFT);

So it says BOTTOMLEFT and it fixed it for my application. When I read and display data with LibTiff it works. BUT! It doesn’t display properly in windows image viewer. Is it safer to just flip data order?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T09:05:18+00:00Added an answer on June 14, 2026 at 9:05 am

    Windows bitmaps are stored with the bottom line first. Basically they use Cartesian coordinate system which puts point (0,0) in the bottom left.

    So, you are probably should just adapt the for loop in you code that writes scanlines (make it write scanlines in inverse order).

    Using TiffTag.ORIENTATION tag is a solution too, but the problem is: most viewers ignore this tag completely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.