I need to adjust the image to 30 by 30 pixels, while depending on the size of the original image, reduce or enlarge it, the aspect ratio of the original image is not important. For example, take a character (letter, number or punctuation mark) in the form of an image of arbitrary size and at the output we get an image of 30 by 30 pixels, where this character can be recognized. I am writing in C # Tell me, please, an algorithm or a built-in method that will help me.
2 answers
If you are satisfied with a deformed image, for example, you can use the Windows Forms System.Drawing.Bitmap class.
// Загружаем исходное изображение var image1 = new Bitmap("image.jpg"); // Масштабируем до нужного размера var image2 = new Bitmap(image1, 30, 30); |
What is the difficulty?
Looking for what you have more - length or width. Let the greater of the length and width be s . Scale the picture with a factor of 30/s .
- Thanks for the advice. I need to get a picture of the symbol, where the top line of pixels would be filled and so with all four sides, that is, the picture should be cropped so that there is no emptiness on either side. I can't figure out how to stretch or compress the images so that it is always 30 to 30. - petrichor
- pp.vk.me/c604625/v604625676/11b04/exnM9Cn3ERE.jpg source - petrichor
- pp.vk.me/c604625/v604625676/11b0b/YO-sco7M5Rw.jpg received - petrichor
- 30 to 30 will not. When you calibrate, one of the measurements will be 30, and the other less. Complete with white or transparent pixels on the sides (or top / bottom). - VladD
- The fact of the matter is that at the output I need a stretched image, but without white or transparent pixels above or below. - petrichor pm
|