Increase the resolution (dpi) of an image

喜你入骨 提交于 2019-12-12 12:10:18

问题


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?


回答1:


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);



回答2:


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).



来源:https://stackoverflow.com/questions/11648388/increase-the-resolution-dpi-of-an-image

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!