How I can create and save png-image in Windows8/C#? I find way without DirectX. Is there a way to render the set of XAML-primitives to png?
You can use the BitmapEncoder class to create a PNG image. Use the PngEncoderId as the Guid argument to CreateAsync. See this sample. See this sample for an example of how to save data.
There is no easy way to pickle the visual tree into an image like there is in Silverlight.
Related
I want to copy an image with all its parameters, including the manipulation data (scale, rotatio etc).
I'm creating a new image control and copy the source and size but can't find a way to set the same manipulation data.
I'm using System.Windows.Controls.Image and i have the ManipulationData object of the source image.
Have any idea?
Thanks
There's very good nuget package available for this..
https://www.nuget.org/packages?q=Tags%3A%22Magick.NET%22
For example to crop or resize an image:
MagickImage image = new MagickImage("filepath.jpg");
image.Crop(new MagickGeometry(424, 448, 224, 224));
image.Resize(123,234);
image.Write("output.jpg");
You can use RenderTargetBitmap to render any UIElement to bitmap:
The class exists in both, WPF and Windows Store Apps, however the usage is slightly different.
WPF Links:
- https://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap(v=vs.110).aspx
Windows Store Links:
https://msdn.microsoft.com/library/windows/apps/dn298548
http://social.technet.microsoft.com/wiki/contents/articles/20648.using-the-rendertargetbitmap-in-windows-store-apps-with-xaml-and-c.aspx#Use_its_Pixels
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
I'm kind of a greenhorn to Windows Phone development and I've been looking for a way in order to crop an image already built into the project (Maybe even from the camera some day), but every package I've found has either had a fuss with Visual Studio, or throws argument exceptions. So I've decided that I will make my own function to do so.
However, I have not the slightest idea where to start. I'm pretty sure WriteableBitmap has something to do with it, and something to do with the following code:
Application.GetResourceStream(new Uri("/PhoneApp3;component/Assets/Flowers/Daff.jpg"));
So how would one start out with getting the pixel data or creating a new image and apply pixel data. And finally how would one save the result and reference it through the UI's image elements.
Use WriteableBitmapEx to crop images on Windows Phone. The way you solution will have to work is to manipulate the WritableBitmap.Pixels property. You first load in an image, change the Pixels property and transform the raw pixels into a saved image format like JPG or PNG. That's a lot of work so lucky for you WriteableBitmapEx does that for you.
First, install WritebleBitmapEx from NuGet:
Install-Package WriteableBitmapEx
Then you can load any image, crop it and save back to the MediaLibrary. Here's for example how to load a file from the app's XAP, crop to top-left 25% of the image and save to the "Saved Pictures" WP7/8 album.
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
var bmp = new WriteableBitmap(0, 0).FromContent("Assets/ApplicationIcon.png");
var croppedBmp = bmp.Crop(0, 0, bmp.PixelWidth/2, bmp.PixelHeight/2);
croppedBmp.SaveToMediaLibrary("myImage.jpg");
}
When we run this code we can see the new cropped image:
I recently needed to do this and didn't want to use an external lib. Microsoft provide a good example on MSDN on how to do it (and is also very good at not causing memory leaks!)
http://code.msdn.microsoft.com/wpapps/Photos-Sample-a38a2c8e
Cheers,
Will
How do i generate an image and draw it in C#?
I am generating an image then allowing the user to further modify it by clicking the imagebox.
This is an editor so i shouldn't need any directX? whats the easiest way to generate a bitmap and draw it to screen?
You need to use the GDI+ libraries found in the System.Drawing, System.Text, System.Printing, System.Internal , System.Imaging, System.Drawing2D and System.Design namespaces.
http://www.c-sharpcorner.com/UploadFile/mahesh/gdi_plus12092005070041AM/gdi_plus.aspx
Using VS2005 and C#.
Having a button in a form and an image from a resource, the image does not have transparency.
How can I have transparency when assigning the image from the IDE ?
Thank you.
Open the image in an image editor (Paint.NET and GIMP are free) and add the transparencies wherever you need to.
It will all work once the image actually has transparent pixels.
You can also use a couple methods of the Bitmap class to do this:
Bitmap b = Properties.Resources.MyImage;
b.MakeTransparent(b.GetPixel(0, 0));
I don't really understand what you are asking. You can use an image with transparency on a button as long as the image type you are using supports transparency - such as .png.
Edit: I read your question again and it is still confusing, but maybe you meant to say that you want to add transparency to the image? If so, you would have to use an image editor to add the transparency and save it in a format that supports this. Paint.Net is a good free tool for this.