views:

334

answers:

1

Hi all.

I am trying to reverse the output being sent to a label printer to match the preprinted paper that it is preloaded with.

Some of the printing is done by sending rich text to a Graphics.GetHdc(), the rest is via use of Graphics.DrawXYZ() methods.

Because the Matrix class ignores anything sent directly to a device context, I have used a bitmap to draw on. I can then rotate the graphics object using the Matrix.RotateAt() and then draw the previously drawn on bitmap on it. Problem is, by using a bitmap, the printed output is less than desirable (very pixelated to say the least). I did play with the SetWorldTransform() method, but this seems incompatable with Graphics draw methods. I have been going around in circles and going out of my mind here.

I have butchered the applicable code from the program to make an example of where I need help. Not sure if it will compile, but it should all be there (should be good enough for demonstration purposes anyway). This method would be called from the PrintDocument class.

private void OnPrintThePage(object sender, PrintPageEventArgs e)
{
    float mmTo100thInches = 1.0f / 25.4f * 100.0f;
    int width = 60 * mmTo100thInches;
    int height = 120 * mmTo100thInches; //  mm converted to 1/100th inch
    Graphics g;

    Matrix m = new Matrix();
    m.RotateAt(180f, new PointF(width / 2, height / 2));
    e.Graphics.Transform = m;

    Bitmap bitmap = new Bitmap(width, height);
    bitmap.SetResolution(300, 300);

    g = Graphics.FromImage(bitmap);
    //g.Graphics.DrawXYZ()...

    e.Graphics.DrawImage(bitmap, 0, 0);
    e.HasMorePages = false;
}

Without the line:

bitmap.SetResolution(300, 300);

It prints as it should, that is upside down and correctly scaled, but looking pixelated. With that line in place, the printing looks quite good and orientated correctly but at about a quarter the size it should be.

I would be most grateful it somebody could tell me where I am going wrong. I have tried to adapt an example out of Charles Petzold's "Programming Microsoft Windows with C#". He explains the need to match the resolution to the bitmap to the printer DPI. I just cannot make it work.

Regards,

David.

A: 

Help!! I am desperate here...

David