image problem in wpf (image does not show up) - c#

I don't understand why I cannot display an image in WPF. Maybe I modified my resources folder accidentally and that is the reason why I does not get displayed. So I created a new wpf application and I have this:
and when I run the program my picture gets displayed as:
Why is it that when I try doing the same thing in my program the image does not show up!?
note how when I run the program there is no image...
In my other application I just dragged the image control to my main window and then I browsed for a random image on my computer and when I complied and run it it works fine. Why is it that I cannot do the same with the application that I am working with?
EDIT:
with some images it works and with others it does not! why?
take a look:
and when I compile and run one image does not show up!
and also take a look and see how the files have the same properties.
settings for folder image:
settings for mov image:

Chances are the Image does not have the Build Action set to Resource. If it's anything else, including Embedded Resource, then it will not display properly at runtime.
Other things you can check are the the resolution of the image. In Paint, you'd use File>Properties to view the resolution.
Try saving as a different format, such as jpg. If that works, then it's likely a problem with your file.
You may need to clean and rebuild your solution as well.

I fix it and I don't understand why it works. I need to add this information for my sqllite connection to work. I just had to comment this out:
and it worked. Maybe this is a bug of sqllite that I should report because those lines where added when creating the connection with visual studio.

.BMP Image format is not supported. I had the same issue but after converting the image to .jpeg format it worked properly.

Related

Trouble opening cshtml file

I have an mvc project while working on it i have opened a cshtml file, then unexpectedly my pc was crashed and restarted, now when i want to open the same cshtml file it opens like the image i have shared
when i open the url in the browser i get this error as bellow image
any help please
I'm not sure what your question is, since you only describe a problem and not specifically what you are trying to do.
But since it's been 20 minutes and nobody is answering, I'll try to help. (I do not have enough reputation to post a comment, or I would have)
The screen in your sample is Visual Studio's binary editor. Your file seems to contain only zeroes, no data. That probably means the file is corrupt. I assume Visual Studio defaults to the binary editor in this case because the file does not contain any text that is possible to display.
I think you'll have to delete the file and restore it from your source control system. (Hopefully you didn't have a lot of work in that file, because it is probably gone.)

Some of the images are not coming after Publishing WPF application

I have published my WPF application using ClickOnce publishing method. I ran the application on the client PC and I noticed that some of my images are not appearing e.g. Background images of Windows. I looked carefully and found out that one Sample.jpg Photo is properly showing inside the Image container which I've used for every record.
Same goes for another image n still coming. The problem I am not able to figure out why both these two images are coming and not the background one?
While creating the Application I have put all the images in a single Folder and all images are referenced from this single folder only.
I also tried by simply copying my project>BIN folder files to client machine and yes, all images are loaded properly without any issues. The problem is only coming in the publish version of my application.
Could anyone help me in this? are there any settings I should take care of while deploying the application? Or I should move them to any specific location?
Are your images Build Action property set to content and the Copy to Output directory property set to Copy always/Copy if newer?

How to use a Resource Image in Word document?

I'm working on a project that will auto-generate Word and HTML reports. If they don't provide an Image to use in the header of the Word report, the customer wants to use their logo. I have the logo stored in the resources of one of the projects as a .jpg.
The method to add a picture to a range needs the path as a string to the image, without any overloads. I know that when a file is added to the resources of the project, it doesn't exist as it gets embedded inside the .dll that gets created. Is there no way to utilize that embedded resource in that method?
Do I need to copy that file as part of the install to the directory? I'm thinking that may be the easiest solution, however what should I do for testing purposes?
I was making this a lot harder than it needed to be.
All you have to do is make an image object from the resource:
Image img = Data.Properties.Resources.ImageFile;
Then after that, all you have to do is save it:
img.Save(#"C:\DestinationFolder\Image.jpg");
Now you have the file to use however you want. It won't matter if you're in debugging or not (as far as your Application.Run location) in the event you have it in a subfolder in your project (as you should), but wouldn't necessarily have it in the same path at the end.
I was way over-thinking this the other day when I asked this question. Hopefully I'll be able to help someone else out who's having this same issue.

Reading a Bitmap from a TIF file - Works in WinForms not in ASP.NET

EDIT Solution Found: See my post below.
We are writing a library that reads in a TIF file from a scanner. Basically, its a scantron. We are examining the form and reading values from it.
Currently we have a windows test app, and we give it a filepath as a string ("c:\testing\image.tif"). It loads up the tif, reads the document correctly and parses the values.
We also have an ASP.NET web application. We have a test page that does exactly what the windows app does, we hand it an identical string, and i calls the same function on the same class from the same library. It however does NOT read the form correctly. We have verified that it does it fact load up the tif file, and it is actually filled with data (pixels we expect to be white/black are white/black when we examine the Bitmap obect in the immediate window of Visual Studio).
The specific problem is in a library called DataMatrix we use to scan a bar-code off the document. This function is supposed to return a List<string>, each of which is a barcode the library found on the document. In the windows app, this function (DataMatrixDecoder.DecodeBarcode(bitmap)) correctly returns with a Count=1. When using the asp.net app, this returns with Count=0.
Because its the exact same image file, I cannot imagine the problem is in DataMatrix. I can only assume its something with ASP.NET or something.
This isn't even my project, but another guy and I are helping our coworker figure this out, and we are just pulling our hair out. All signs indicate that ASP.NET is correctly loading and handing the image off disk to the "processor" class (which is a class library that uses the DataMatrix stuff, we are not doing ANY code in ASP.NET except for opening/handing the file to the function.).
Does anyone have any ideas as to what it might be, or different things we can check?
I'm not even sure what kind of information to give so I tried to say it all, if you have any questions please ask I'd be more than happy to elaborate on anything. Thanks.
edit:
this is the code on the ascx.cs code-behind, in a button-click event:
if (formReader.ReadTIFF(#"c:\testing\image.tif"))
{
messages.Controls.Add(HtmlHelper.DivSuccess("Read successful."));
}
The formReader class then open the file with a FileStream, and uses that to create a Bitmap. The ASP.NET application is not actually opening the file at all (we were uploading it through a FormUpload control, but after experiencing problems we dummied it down to this). This is the most perplexing thing, that it works in the windows app but not from this web site. ASP.NET has full permissions on that folder to do whatever it wants. It can open the image fine, and the bitmap it creates from the FileStream is the actual image.
edit: Also, the ReadTIFF function right now copies the FileStream into a MemoryStream, ensuring its a not a problem streaming from disk (the entire file is in memory).
How are you passing the filepath to the web application?
It is possible that the function which Decodes might be swallowing some exception.
Use reflector to examine the library (if you have not written it).
I agree. It seems your problem is most probably related to User rights on the directory where you're trying to access the files from. Try giving your Web users the Full access rights on the source directory.
EDIT
Solution Found: The problem was that the open file dialog was changing the CurrentWorkingDirectory. The reason the website never worked, was because the Environment.CurrentDirectory was set incorrectly. When I manually set the CurrentDirectory to the websites' bin folder, parsing works correctly.
Small update. Using the Windows App, and selecting the file via OpenFileDialog, will cause the barcode decoder to fail. Technically, I am using the exact same string to hand to the parser ("c:\testing\image.tif"), yet when I use the OpenFileDialog to get the string, the decoder fails. Is there a clue in this?
update: In fact, even if I don't use the string the OpenFileDialog gives me, if I just open the file dialog at all, it will fail. I don't get this. It's something simple. I need to debug the C++ DataMatrix library, really.

How to parse an .msstyles file?

I need to extract some bitmaps from an .msstyles file (the Windows XP visual style files) and I'm not sure where to start. I can't seem to find any documentation on how to do it, and the file format seems to be binary and not easily parsed. I have been able to extract the bitmap by itself using:
IntPtr p = LoadLibrary(UxTheme.ThemeName);
Bitmap bmp = Bitmap.FromResource(p, "BITMAP_NAME");
FreeLibrary(p);
However, I also need the information related to the bitmap, like the margin sizes, spacing and number of "images" per bitmap. Does anyone have any experience with this or any links to documentation that I can use?
This site claims the file format is documented though not by Microsoft.
Also found this in the Wine Crossreference.
Hope that helps!
If you want to get files out of a dll directly (remember, msstyles are dlls with another extension), you could have a look at the Anolis Project.
As for actually parsing that stuff you should look at the various tutorials on creating msstyles for information on how the various text resources in that file work.
This codeproject article seems to have exactly what you want, with a little interop involved. A managed wrapper exists and it seems rather good. The .Net WindowsForms also has the functionality built in, you might want to look at the System.Windows.Forms.VisualStyles namespace if you want simplified read only access.
You can open the msstyles using 7-zip, install it, then right click the msstyles > 7-zip, ther's 2 open inside, one as a normal button and the other with a arrow, choose the second one, then select "#"
You're now inside the msstyles, now right click to 1..mst > Open inside
You're inside the actual theme now, now just extract it's resources
Image of the msstyles open (is in spanish tho)

Categories