Question

I'm not sure how feasible this will be without some thirdparty libraries, but here goes:

I have an image, 450x900 in size, which im trying to print.
The problem is, the method I'm using to print is sending raw data to the printer.
The resolution of the image is 96dpix96dpi, the printer runs at 203dpi.
So... the image comes out small.

I need to increase the dpi of the image to print it at its 'real' size.

Bitmap b0 = LoadBitmap();

//I need to rotate it because for some odd reason it prints backwards and upside down.
b0.RotateFlip(RotateFlipType.Rotate180FlipX);

//Set a new resolution, 203dpi
b0.SetResolution(203, 203);

//I need to save and reload the bitmap, because RotateFlip compresses it.
//(annoying as hell, took me ages to figure out why it wasn't working.)
Stream imgStream = new MemoryStream();
b0.Save(imgStream, ImageFormat.Bmp);
b0 = new Bitmap(imgStream);

//get my byte array
ImageConverter converter = new ImageConverter();
byte[] imageData = (byte[])converter.ConvertTo(b0, typeof(byte[]));

So, fairly straight forward. But SetResolution(...) doesn't actually seem to do anything. The image prints exactly the same size, and the resultant byte array is exactly the same size.

So I'm trying to work out what it is actually doing.
But I guess it would need to pad out all the image data with extra pixels to do what I want it to?

If this isn't a practical method, is there a simple stretch method or similar I can use to get the desired effect?

Was it helpful?

Solution

Why not scale your image to be bigger:

        System.Drawing.Bitmap b0 = LoadBitmap();
        double scale = 203/96;
        int width = (int)(b0.Width * scale);
        int height = (int)(b0.Height * scale);
        System.Drawing.Bitmap bmpScaled = new System.Drawing.Bitmap(b0,width, height);

OTHER TIPS

You have to understand that simply changing resolution (dpi) of a bitmap does nothing to its pixel content. For bitmap "resolution" is only a metadata. What really matter is size in pixels.

So if you want your picture to be bigger in print you'll have to either change printer resolution or scale your image (for example, using Grzegorz's method).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top