Save Chart as an image on Hard Drive - c#

I am looking for ways to save the output of a Chart control as an image on the hard drive. Is it possible in SL? as I am not sure so thought of putting a question here..
Thanks...

have a look here: Can I programmatically capture snapshot of a Silverlight User Control?
You can simply take a screenshot of your chart. If you want to put in on the HD with silverlight you need to open a SaveFileDialog. Then it is possible.
EDIT: If you want to save it in different formats use ImageTools. http://imagetools.codeplex.com/. If you use ImageTools you can get a stream like this:
var editBitmap = new WriteableBitmap(1024, 786);
editBitmap = new WriteableBitmap((int)(this.RenderSize.Width), (int)(this.RenderSize.Height));
editBitmap.Render(this, new MatrixTransform());
editBitmap.Invalidate();
var myImage = editBitmap.ToImage();
Stream stream = myImage.ToStreamByExtension("png");
Hope this helps.
BR,
TJ

Related

Displaying an image that is stored in the solution c#

I want to display an image in a picture box which I have saved in my solution folder.
Is there an easy way for this to be done? I have seen examples of loading from resources using streams etc. But that seems far too much code for what I'm trying to do.
if (ds.Tables[0].Rows[0]["GDPRState"].ToString() == "1")
{
picture_GDPR.Image = Image.FromFile("");
}
Do I want to be using the FromFile function to achieve this?
https://www.youtube.com/watch?v=LQMDsJgMXhE
The above YouTube video helped explain it to me.
I had just copied my image into the directory and not added it as a resource. When I had added it correctly the following code worked.
picture_GDPR.Image = Properties.Resources.gdpr_test;

C#/XAML - Assets not shown when modified by code

I created a user control, which is made with images.
I tried to modify them by C# method, for example:
imgElement.Source = new BitmapImage(new Uri("ms:appx/Resources/IconElement/my_icon_element.png"));
imgBackgroundElement.ImageSource = new BitmapImage(new Uri("ms:appx/Resources/BackgroundElement/my_background_element.png"));
The soft finds images but doesn't show them ; the image control is empty.
If do not use the method and let images by default, they are shown...
Can anyone teach me why ? ^^
Thanks !
An absolute path for your image will be:
ms-appx:///Resources/IconElement/my_icon_element.png

How can I change an image/bitmap that is already in use?

I have a directory with .png images which I display in a third party combobox of my c# program. So the user is able to choose one of this images using the combo box. Basic code used:
Bitmap thump = new Bitmap(<path>);
ComboItem item = new ComboItem();
item.Image = thump;
MyComboBox.Items.Add(item);
Now I would like to update one of this images at runtime. Unfortunately I can't delete the old image because it is still opened in my program, so somehow I either need to close it or open it in a way that does not keep the image in use by my program. The changes to the bitmap are not done in my program, I just pass the path of the dirctory to another program which saves the bitmap there (but fails at the moment because it can't delete the old bitmap).
I guess this is a simple problem but I could not find a solution here or on the internet.
First read the file to memory, then create the Bitmap using that data.
var m = new MemoryStream(File.ReadAllBytes(filename));
Bitmap thump = (Bitmap)Bitmap.FromStream(m);

pre-visualize an image

I'd like to pre-visualize an image in a image box before save it in a directory.
How can i do this, i use a checkbox to see if the user wants to pre-visualize or not because i dont find another way to do this without a checkbox.
I use file upload to upload the image.
string serverFileName = "";
serverFileName = Path.GetFileName(Upload.PostedFile.FileName);
Upload.PostedFile.SaveAs(MapPath("~/fotosPerfil/") + serverFileName);
i use this piece of code to save the image.
I think this post is exactly what you need to implement. Check out Ivan's solution.
Yes, indeed you can read the path selected by the user and display the image in an <img> tag, all client-side prior to uploading.

open picture in new tab, same as if do right click - View Image in firefox (WatiN)

I need to open image in new tab exactly as it's being done by clicking right button on it and then selecting View Image in firefox. Copying pic url and using browser.Goto doesn't give me the result i need due to some tricky javascript. Could anyone give me some suggestions? Thanks
Old question, some answer for reference only.
Get the src attribute for the image you are looking for and then open a new instance of IE with that address (you will probably need to append the base website address plus whatever there is in the src attribute for the image you are looking for. Some code for that:
Image btnLogin = Window.Image(Find.ByName("TheImageNameOrAnyOtherAttribute"));
string imageAddress = btnLogin.GetAttributeValue("src");
var newBrowser = new IE();
newBrowser.GoTo("http://www.somesite.com/"+imageAddress);

Categories