I'm currently working on a fractal generator in C# and I'm trying to export my set of coordinates to a very simple image file.
What i have is a 1-dimensional array of 3d point (x, y and z coordinate) and i wish to save it to an image where the z value will be the color of the pixel (grayscale only).
From what i gathered, the RAW format would be the easiest to work with, but even then i couldn't find documentation on it. I then looked at the namespace System.Drawing but i'm at a lost, it seems overly complicated for what i'm trying to achieve.
Is there an easy way to write such an image?
This link should help explain how to create an image pixel by pixel:
http://msdn.microsoft.com/en-us/library/system.drawing.image%28v=vs.80%29.aspx
then you should be able to use image1.Save with a string argument of the file location.
If you just want to display it on a winform, then you could keep the original source code from the link.
You can create a new image instead of loading one like so:
System.Drawing.Bitmap myMap = new System.Drawing.Bitmap(200,300); //200x300 pixels
Related
So I've gotten to the portion of a 2D XNA-based top-down hack-and-slash project I'm working on where I need to draw text onto the screen. What I want to use is a SpriteSheet-esque image I found with the characters and symbols I'm going to need for this project.
Now, I've done a little bit of reading on this before asking, and the only two ways of putting a "Font" or something onto the screen is by using Fonts already installed on the computer, or, according to this, I have to create a Custom Content Processor?
My question is, if I have an image (say, in PNG format), that has all the letters/characters I want on it, how do I use those letters in my 2D game? And it doesn't necessarily have to be an XNA-based solution.
Thanks in advance.
You draw it exactly how you would draw any other sprite from a sprite sheet.
You might already know that the SpriteBatch.Draw method has some overloads that can take a Rectangle that represents the source from your sprite-sheet.
you can keep track of your relation from chars to sprite rectangle with a dictionary
Dictionary<char, Rectangle> fontDict = new Dictionary<char,Rectangle>();
fontDict.Add('A', new Rectangle(/*params representing source of A*/);
and you can your word with a for or foreach loop
for(int i = 0; i<str.Count; i++)
{
Rectangle spriterect = fontDict[str[i]];
SpriteBach.Draw(/*params*/);
}
Keep in mind that you also have to manage the spacing of the letters out on your own, but it's possible to do on your own.
It does however Look like the ContentManager supports creating SpriteFonts based off of image formats such as jpg and png, so I'd say you might just be better off exploring that
further googling yields the FontTextureProcessor Class, which might be helpful.
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
hi i'm making photo mosaic creator but i can't replace a pixel with a set of pixel if any one know how to do this in c# please help cause i'm beginner in c#
and i understand the idea but i can't implement in c#
the idea is we have a input photo and we have a data set of small photos and we create an empty output photo and we put inside here the small photo from the data set after we take the pixel average RBG color from the input photo and we take the average RBG color of the small photo then we replace the pixel with the photo that have the same RGB color of the pixel and sort the small photo's in the output photo
Well, you don't "replace a pixel with an entire picture" when building a mosaic digitally. Instead, you create a brand new output image that is much larger than the input. Then you think about a grid on the output so that each input pixel corresponds to a grid square in the output. You then copy an image into each grid square, checking the corresponding input pixel to find out what image is appropriate.
I have not used it, but WriteableBitmapEx is a class for creating bitmaps and has a SetPixel method.
I'm trying to Bezier-smooth a time series and convert it into a greyscale bitmap of its chart. To clarify, I essentially want C# to take a time series of data, virtually plot a smoothed chart a la Excel, convert this chart into a greyscale bitmap, and output the 2D numeric array of pixel values.
GDI+'s DrawBezier function seems to only directly create a visual display as output. If I redirect its output to an Image object, I think I can convert that into a pixel value array.
Are you sure you want to use Bezier? I can't imagine how you would use Bezier curves to approximate data. Perhaps you want Polynomial Interpolation?
As for drawing the cart, perhaps you should look into one of the many free charting libraries for .NET, like this one http://www.ujihara.jp/jbyjsharp/jfreechart/ (have not tried myself).
I have an image that I get and attempt to load into a graphics object using Graphics.FromImage(image), however this throws an exception if the image has an indexed pixel format.
Is there a way to safely convert an indexed image?
Update: Thanks to Joe for the tip to just draw the old image over the new one, instead I was trying to convert it. This makes a lot of sense.
One easy way is to create a new image of the same size (with a 32-bit pixel format). Then create a graphics object for that image and draw the original on top of it.
what you can do is based on the indexes u can calculate the euclidian distance in the 3 channel color space. Then find the closest color and use those values for your new image.