This project is read-only.

Create QR Img with custom size

Feb 9, 2012 at 2:31 PM


I'd like to generate the QR in a file or stream with custom size but i can´t find a way to do that. Is there any way I can do that?? I found the Measure function in the Renderer class

public Size Measure(int matrixWidth)       


int areaWidth = m_ModuleSize * matrixWidth;           

m_Padding = quietZoneModules * m_ModuleSize;           

int padding = m_Padding;           

int totalWidth = areaWidth + 2 * padding;           

return new Size(totalWidth + 1, totalWidth + 1);


I didn't understand why is doing that to calculate the size. I´d like to tell via a paremeter, for example with the value "200", the size of the QR Img (so that the size would be 200 x 200). Is there anything I'm missing to do that??

(Sorry for my english)



Feb 9, 2012 at 4:08 PM

I forgot to mention I need to do this because I'm doing a web service that receives text and size and returns a QR code for that text in the specified size. That QR code that returns the web service is directly embedded in a webpage.

Thanks Again


Feb 10, 2012 at 4:23 AM

Currently you can only use module size to specify the actual display size of QrCode. 

Number of modules for width will be matrixWidth + 2 * QuietZoneModules.

Pixel width will be number of modules for width times module size.

Above Measure method is mess, It's from original demo which I should replace with newest code. Proper one you can find under WPF version of renderer class. 

matrixWidth is determine by input text.  

Create a image then resize probably is more accuracy than draw according to specific size. Easiest way probably will be HTML's stretch function. 

<img src="image.jpg" width="200" height="200">

That will display any image with size 200x200.

Just make sure to give proper module size to renderer. Module size too big will cause image size way too large. Module size too small, stretch hard out, small QrCode will display poorly. 

Feb 10, 2012 at 2:26 PM

Thanks for the comment. I'll try to implement the solution you mention.

It'd be a good enhacement to be able to select the size of the QR when you generate ir to a file or stream. I hope you keep that in mind for the future if it is possible.

Thanks again! You're doing a great job! It's the only serious open source component that I've found for Net. It's full of QR generators in PHP but nothing good for Net (except this one =) )

(Again sorry for my english)


Feb 10, 2012 at 5:40 PM

Hi. I'm glade you like it. 

I have thought about it before, but as matrix size is controlled by input string, so module width might be decimal. There is no decimal pixel, result will cause a single square module to display like "gray, black, .... black, gray". I could do some tricks, where QuietZone is not constant, but that might make it looks ugly. Anyway I will give it a try later. Thanks for suggestion. :)