I have a WinForms app that takes a screenshot, and I want to be able to view this screenshot. Originally I was creating a new instance of a PreviewForm which contained nothing but a picturebox, but if the image being previewed was large, the screenshot is kind of useless.
I'm aware of defining a filepath and using Process.Start(), but this would require this screenshot being saved locally before opening.
Is there no equivalent method to open an image in image viewer from just a bitmap object?
I find it would be easier if you just saved it and opened it with a software. I tried to find many different ways to not save the file, but there aren't any unfortunately, so I have to save it and open with a tool like this: http://www.paintshoppro.com/en/pages/bmp-file/
Related
I have a C# program that I need to embed an image into or perhaps better stated make the exe file portable such that the image will open on any computer and I need the image to open up in the default picture viewer (not a form PictureBox). I do have the image in the resource folder with 'Embed Resource'
System.Diagnostics.Process.Start = WindowsFormsApplication5.Properties.Resources.MyImage;
I realize the above code is invalid, but I am just a coding hobbyist, so I don't know everything. If I could get a little push in the right direction, I would appreciate it.
This might do the trick for you but If you want a Default Image Viewer to open a picture, you need to store that image to somewhere on your disk, thus the Image Viewer could find and open your picture.
var bitmap = new Bitmap(WindowsFormsApplication5.Properties.Resources.MyImage);
bitmap.Save("YourImageLocation");
Process.Start("YourIamgeLocation");
I use a Flex app (SDK version 4.14.1) to take a photo from a camera on Android, and I pass the resulting ByteArray to an .net c# script that writes the image to a directory and sets the name etc.
I can see the file in the file system, I can open the file in the file system (with either a jpg or png extension, I believe that browsers can do this though), but when I add an Image control to Flex and point the source to the path of the image, I just get that annoying missing image icon.
I was guessing that it was to do with extensions, as the image is sent straight from the camera as a byte array I kind of had to guess the extension, but whatever it is can you help me solve it please?
For reference, the image is stored on an IIS web server, but it isn't cross domain policy that is stopping it because if I drag the image into my project and bind it directly it still does the same thing.
Ideally I need to use Image and not BitmapImage, but if it can't be helped then I can change.
Thanks
EDIT
Changing from Image to BitmapImage kind of worked, kind of because the image now shows in the desktop debugger, but on device it just shows blank. Any thoughts on this?
In the spirit of making sure all of my questions get an answer I am going to settle on the solution of using BitmapImage. Every other part of the design is correct, I cannot see anything I am doing wrong, and although using BitmapImage causes me an issue with missing image and placeholder image, it is a solution after all.
I have a problem with converting *.fig files (from Matlab) into bitmaps (or any type which I could use in pictureBox) using C#.
I need to read this file somehow and then show it in pictureBox.
I tried several ways, for example:
Image img = Image.FromFile(fileName);
Bitmap bmp1 = new Bitmap(img.Width, img.Height);
But I got an "Out of memory" exception thrown in the first step.
Do you have any ideas how to do it??
I have a proposal:
Instead of a picturebox, put a panel on your windows form. Then, use System.Diagnostics.Process to start the matlab viewer (required dependency for this, sorry).
Now, you can use the instructions here to get the windows handle for the main window of the viewer:
How to get main window handle from process id?
Next, change its parent to the panel in your windows form.
http://support.microsoft.com/kb/89563
I've used this trick before and it takes some tweaking, but you can capture another process's main window and make it a child control on your form. If you can find a less messy way of doing this, that would be great.
The out of memory exception also occurs when the image file is not in the correct format.
http://msdn.microsoft.com/en-us/library/stf701f5.aspx
It's likely you'll need to use some tool to change the .fig file into an image format. I'm not sure how Matlab saves .fig files, so you'll need to do some research as to how the file is actually stored, or find some third party software to update your file to a viable format.
I'm working with a WinForms app. I have an RDLC report that will be printed on 11x17 and then folded (printer supports folding). I'm rendering to EMF and drawing to pages of a PrintDocument. This works fine except for folding.
What I'd like to do is store the settings that make the printer fold. The users would select a preset from a dropdown and the app would select the printer, the paper size, the tray, whether to duplex, and whether to fold. Storing the PrinterSettings object covers most of this, but doesn't save the folding option.
I first attempted to store/retrieve something I read about called DEVMODE. For reference: http://nicholas.piasecki.name/blog/2008/11/programmatically-selecting-complex-printer-options-in-c-shar/. What I found is that even though I had extra data specific to the driver, all the bytes were 0 regardless of what driver-specific settings I changed. I'm not sure where I went wrong with this, but I abandoned it and looked at the printing capabilities in WPF.
I found that I could configure a PrintTicket for my settings, store it, and retrieve it later. It seems a bit convoluted just to save the settings, but I think I have it working. At least it seems to show up correctly in the PrintDialog. However, I'm now stuck trying to figure out how to print my report.
As I understand it, I can't take a PrintDocument from WinForms printing and use it in WPF. I also read EMF format is not supported in WPF. I thought I would render each EMF to a bitmap, then print those. But the text in my report is fuzzy and I'm not having any luck clearing it up.
Starting with a stream that contains EMF bytes that I know will render sharply with PrintDocument, I test trying to save to a file. It seems no settings that I provide will save with crisp text.
var pageImage = new Metafile(stream);
pageImage.Save(filename);
All this just to add the ability to fold. Am I just completely on the wrong track? I don't see how this should be so hard. I guess I either need to find another way to save/restore custom printer settings or I need a way to render these EMF files better.
I also tried rendering the report directly to BMP format and it's also poor quality.
I tried something slightly different and it worked! I reused my original PrintDocument code and printed to an XPS file. Then I printed the XPS file using my PrintTicket and it works fine.
How I can open the image saved in database directly using Internet Explorer (Not WebBrowser control in WinForm/WPF) without saving it to a file first?
I think this is not possible unless you create a web page or something similar to display the image from a temp file
Search for Process.Start look at the site...
MSDN
This gives you the exact example of opening a file in IE, you might need to save your image into a temp file on the disk