How can I save an HTML string to a Bitmap \ Image? - c#

I made a program that converts an image to ASCII based webpage.
http://postimage.org/image/2pi49sa4k/
That image was rendered using Chrome, on 50% size (miminal).
Obviously, I can make it myself because the code is only based on the FONT tag,
but I believe that it'll make things more complicated, as I'm not too good with graphics etc.
I would like to know how I can convert that string to a Bitmap or Image, with some parameters.(like size etc)
Thank you !

Related

TextureBrush low quality printing

I'm creating an image with some text and using TextureBrush for draw the text along a line repeatedly. It is working fine on the screen. when i want to print it, it looks very bad.. I've tried to create the image bigger (relative to the dpi differences) and set its resolution as the resolution of the Graphics object (For printing it is higher). Printing the image as it is looks good.. but as TextureBrush not so good.
I'm attaching all the prints - Tried to print it to PDF printer - same results as real printer - so no problem there.
first try before changing anything
Drawing the image using graphics.DrawImage(...) (The image contains The letter 'A' that I've drew in)
Printing TextureBrush
At this time it was clear that i have resolution problem so I've created my image bigger and in better resolution (as the printer dpi)
Drawing the image using graphics.DrawImage(...)
Looks perfect - Exact size and good quality. graphics.DrawImage(...) drew the picture with consideration of its size and resolution.
Now I've used this picture in my textureBrush. The result looks like this
It is bigger because the image itself is bigger - But why it does not consider resolution like graphics.DrawImage(...)..
Anyway i've decided to continue and scale down the image using TextureBrush.ScaleTransform(...) - The results looks like that
This is the best that i've reached so far.. I think the main problem is the TextureBrush that does not consider the resolution of the image.
I would really prefer to stick with the TextureBrush way (And not drawing image by image with clipping and repeating), cause it is very complex code, and complex drawing
Help anyone ?

Not getting sharp image of rectangles on canvas

I am parsing a .sym extension font file to get the character shapes. Characters are to made using pixels and hence this font file contains information in such form that it shows which pixel is to be shown in black color and which is not be colored.
I have written logic to draw these pixels using Rectangles on a WPF canvas and everything works fine except for the fact that I am not getting a sharp image.
The purpose ultimately is to take the screenshot of this image of this canvas and paste wherever the user wants it to be pasted hence very clear image is required.
Also, when this image is exported in XPS and zoomed in, I get a very sharp image like below and hence I don't think there is any problem with the character making logic:
I don't understand why this mismatch in clarity is happening.

What type of image filtering/processing do mobile PDF scanners use to convert a captured image into a monochrome/black and white image?

I am trying to implement my own monochrome/black and white filter in C# to scan text documents. My approach is to apply a threshold filter on the captured image. However, I often run into the problem that the varying brightness on the image causes a ''shadowing effect'' on the processed image. Refer to the link below (it is pretty blurry but it should suffice). The image to the far left is the original image. When I apply my threshold filter, I get the same result as the image in the middle; some of the text becomes unreadable because the brightness of the image varies, so some portions become really black or really white. However, with the right filter, you can obtain the processed image to the right where everything looks crystal clear.
https://www.google.dk/search?q=monochrome+image+processing&espv=2&biw=1706&bih=859&source=lnms&tbm=isch&sa=X&ved=0ahUKEwir8vXlhIzPAhUFiywKHeSBC1wQ_AUIBigB#imgrc=4UTzoIpyqTkwrM%3A
I would like to know what the process is to obtain the image to the far right. Another example can be seen in the image below. It shows a sample mobile PDF scanner in use. Scanning the image results in a very nice black and white image, where the text can be easily read and no ''shadowing'' occurs on the image. Does anyone know what this process is or what it is called? It is very often used in mobile PDF scanning applications. Thank you in advance.
EDIT: The filter is called ''Adaptive Thresholding''. You can use the BradleyLocalThresholding class to implement the filter, or you can write it yourself (which is what I did). Please refer to my response to the comment by Yves Daoust down below.
You need two ingredients.
One is "background reconstruction", i.e. retrieving the intensity of the white sheet "under the characters", for instance by morphological opening.
The other is "shading correction", i.e. compensating the unevenness of the background illumination by comparing to the reconstructed background, for instance by subtraction.
This will "flatten" the image, making it perfectly amenable to global thresholding.
A simple method is to convert the image to grayscale and then convert it to B/W using an error diffusion algorithm such as Floyd–Steinberg dithering.

Convert Image to SVG using C#

I want convert Image file (PNG,JPG) to SVG using C#. But I don't want to have image/base64 string in my svg tag.
SVG means Scalable Vector Graphics, which is not an image in the way a .PNG or .JPG is. Rather than storing an array of pixels, it stores a list of mathematical shapes and designs. The intent of an SVG is to create an 'image' that retains quality regardless of how far you zoom in or out.
There is no benefit to converting .PNG to .SVG - in fact, it loses quite a bit of quality because you can't literally "convert" it, you can only trace it (IE, draw a new SVG that looks like the PNG.)
In summary: I think you're asking the wrong thing here, or you simply don't understand what you're asking. Please clarify if you can.
I've used the website below and got great results converting logos and what-have-you to vector formats. I have no connection to them:
http://vectormagic.com/home

Using a System.Drawing.Image as the centered part of a larger image?

I have a System.Drawing.Image that I would like to use as the centered portion for a new, larger image. I’m given the dimensions of the (always) larger image and the idea is to make that image all white and overlay its center with the first image. Is there a way to do this using GDI+? Some combination of TextureBrush and the Graphic class perhaps? I’m open to suggestions. Thanks!
Lots of similar questions, here's one that I think will show you the basics:
How could I position multiple transparent PNGs onto a JPG using c# and asp.net?

Categories