Visual C# Express Monogame load image - c#

I am new in monogame.
I loaded an image using Texture2D background;, then go to LoadContent() method and code background = Contect.Load<Texture2D>("background");. I then imported the image in the Content folder.
After that, I compiled it and got this error:
Unable to load background assets
I checked the Image, and it was background.bmp.
I'll keep on looking for a solution for this.
If you have a solution for me please give me a link.
Any help is appreciated. And by the way, I use Visual C# Express 2010.

Basically you have 2 options, you can either add the content to the Content folder directly (if I understand correctly that's what you have done) or you can pre-compile the assets into XNB files first.
If you are using content directly you will need to add the file extension in code like so:
background = Contect.Load<Texture2D>("background.bmp");
And you'll also need to make sure you set the file to Content / Copy if newer in the properties window inside Visual Studio.
As a side note, if you are going to stick with this method I suggest you save your images as PNG files instead of BMP because PNG has lossless compression and supports transparency.
Alternately, you can pre-compile your content files first to store them in a more optimal file format. See https://github.com/mono/MonoGame/wiki/MonoGame-Content-Processing

Right click on the picture, go to Property and you will see. Copy to output. The default is don't copy you need to turn to Copy Always

Related

C# Wpf embed images at runtime

In my C# WPF application the user have the possibility to import pictures.
Currently the source of the image is referenced to the picture path.
When the picture will be deleted or moved, then my reference is not valid anymore.
How is it managed in applications like Word or Photoshop? Is it possible to embed
the picture at runtime in my custom file? Or should these files copied to a
"image database"?
In Microsoft Word (docx) format. When you paste images in the document, it saves them as file(s). Try this:
Rename the .docx to .zip extension
Extract the zip archive
Now, navigate to the following and you can see all the embeded images here:
You can do something similar for your app. Without knowing the full context and design details its difficult to answer where should the images go.
Generally speaking, images should/could be co-located with the rest of the data that image compliments.

C#, How to Traverse all drive and folder to copy image and paste them in a specific folder?

my project was a image gallery using asp.net.
Initially when then the project load first time i need to copy all the images in the computer and paste them in a folder named Data.
here is my project link:
https://www.dropbox.com/s/sr3qhaamiiwk0di/Gallary_temp.zip?dl=0
https://drive.google.com/file/d/0BynGaI0gi3mrOEtweWlWOEdmSFE/view?usp=sharing
Of course, code must be in c#
Instead of copying the image from hard drive to your location every time, it is better you save the file location in DB and call them when ever you require.

How to programmatically determine if an image file is georeferenced

I have a task to programamatically scan a folder for georeferenced images. There might be a lot of images, some quite large, and some not georeferenced. The spatial information can also be either embedded or in a world file.
How can I tell programmatically (C#/WPF/ESRI Runtime) if "C:\someFolder\file.x" is georeferenced?
Thanks
First check the file type to see if it's a format that supports built in georeferencing (GeoTiff, jp2, and MrSid). Other static image files would need some sort of companion file with the georeferencing information. So for each image file you'd want to look for a matching companion file.
If you add some info on what formats the images/world files are in it'll be easier to show you some sample code.

C# How do I add a jpeg image that I have in my project to an image array

Currently I'm loading the image from the local disk but I would like to embed the image into the program, I have added the image epsonScanner.png to the project and it appears in Solution Explorer how can add this to the array?
images.Add(Image.FromFile(#"E:\epsonScanner.png"));
you should add the image file (epsonScanner.png) to the c# project not just as solution item. after you added, right click on it and set compile as Embedded Resource in the properties window.
after that you retrieve the image from the assembly resources and not by file path, check here for full example on how to do it:
Load image from resources area of project in C#
You can do it in the way you described and answer is already there, but i think it may be easier and cleaner to add Resource item to your project and place images there.
How to create and use resources in .NET
http://msdn.microsoft.com/en-us/library/7k989cfy%28v=vs.80%29.aspx
You can use Bitmap.FromFile(string fileName) method.
try This.
List<Image> imageList = new List<Image>();
imageList.Add(Bitmap.FromFile(YourFilePath));

Insert image in code (.cs) file

Can we insert an image in CS (VS2008) file as an reference to support the complex logic?
The code is quite complex so I want to put the UML image of that code to increase the understanding.
Ram
You can use a hyperlink in a comment.
Example:
// See reference image: http://ourserver.com/documentation/images/reference1.jpg
And it will turn into a working hyperlink that anyone can click while pressing the CTRL key
I guess you want to embed an image inside the code editor?
In Visual Studio you can't do that (maybe there exists a 3rd party plugin which i'm not aware of).
All you can do is to embed some ascii art or add the image as separate file to your project and reference it in your comment.
Yes you can embed image inside the code editor. But the only extension I know it is Image Insertion extension for Visual Studio 2010.
You can get it from Visual Studio Gallery.
You can but for that you will need to create a static byte array and manually fill the array from the bytes of the image file like: static byte[] img = new byte[]{/*all image file bytes*}
I would suggest you to add the image as a resource to the assembly and then you can read it at runtime and do the required processing.

Categories

Resources