I am sorry that this is a little bit ambiguous. I am having an issue using System.Drawing in XNA; from my research it is not available to XNA (since its part of the windows.dll?)
I want to create a sprite sheet analyzer which automatically dissembles a sprite sheet into its proper segmentation, number of frames, etc. for later playback. For this I need to grab the actual PNG file and it would be nice to have something that already has the functionality for working with images. Is there a class in XNA which provides similar functionality as System.drawing?
You can use System.Drawing in conjuction with XNA with no problem -- you just have to add a reference to it in your XNA project. However, System.Drawing does not support loading of .pngs, while XNA does.
The usual way to load images in XNA is to first add them to your content project (usually when you create an XNA project there is always a corresponding content project created). Add the saved .png to your content project and give it a unique name. Then in your code, load the image as a Texture2D:
Texture2D myTexture = Content.Load<Texture2D>("my image name");
Note the use of Content which is a ContentManager object that can be referenced from the Game object you are currently using for your XNA game.
Check this out for more information.
I found the answer. I can actually obtain the color data from the texture2D, allowing me to disassemble an image for analysis without using any extra libraries outside of XNA
http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2D/Texture_to_Colors.php
Related
All that I'm trying to do is to put the DDS on the OBJ captured by the Kinect v2.
I've retrieved the OBJ from Kinect as well as created the DDS texture but unable to put it on the OBJ.
Since I'm new to this ecosystem of Windows and 3D modelling. I'm unable to find any way to get this thing done. Any help would be very much appreciated.
The application is a Windows App using Windows 8.1 SDK and I'm using Helix-Toolkit to load OBJ.
hy,
its little bit late, but may be it will help,
with the .obj file there is a file with .mtl extension in this file you fill find the reference to materials used in .obj file and eventually the reference to textures files .
You will also need a handler for dds files. System.Drawing.Design, can take of this for you.
I've got some C# code in Unity that grabs a large image from my Android Device's filesystem, and now with it I want to use it to create a small thumbnail image.
I've found lots of different suggestions for how to do this such as the following:
MemoryStream outputStream = new MemoryStream();
System.Drawing.Image image = System.Drawing.Image.FromFile(originalImagePath);
System.Drawing.Image thumbnail = image.GetThumbnailImage(thumbnailWidth, thumbnailHeight,()=>false, IntPtr.Zero);
thumbnail.Save(outputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
return outputStream;
However, as with the above method, all of the methods I've found require you to use the System.Drawing namespace. And I can't for the life of me get the functions in this namespace to work on Android, because even after adding "System.Drawing.dll" into the Assets folder, I get an error saying that it can't locate "gdiplus.dll" on construction of "System.Drawing.Image". I tried downloading and adding said "gdiplus.dll" to Assets, but I just get the same error as if it can't find it!
I don't understand why its so hard to get the System.Drawing functions working in Unity, but that's somewhat besides the point, as all I really want to do is create a thumbnail of an image that lives on the user's Android Device. Any suggestions would be welcome!
EDIT: I forgot to mention that I'd like to avoid solutions that use Texture2D's because they can't be run off the main thread, and hence come with performance consequences =(
Thanks in advance! =)
Don't use Texture2D.Resize, because the resulting texture will become grey:
After resizing, texture pixels will be undefined.
See this post for other solutions.
Old answer
I recommend use an opensource C# image processing library, such as ImageSharp or search it on GitHub.
The last solution is to write one yourself, if the performance or size of a 3rd-party library is still not good enough.
Here are two ideas I can come up with:
split the possibly lengthy reading and resizing procedure into several Coroutines.
use multi-thread
You may also try calling java functions from Unity3D. But I'm not familiar with that.
I am Making a Space Invaders Game using Open GL in MonoGame and I am trying to load a texture that I have added to the Content folder (It is a PNG file called "Invader")
The code that I use is:
invader = Content.Load<Texture2D>("Invader");
However when I attempt to run it It says:
ContentLoadException was unhandled could not load Invader as a
non-content file!
I am trying to load a texture that I have added to the Content folder (It is a PNG file called "Invader")
invader = Content.Load("Invader");
Actually, you can load the PNG content that has been added to the Content folder directly like so:
invader = Content.Load<Texture2D>("Invader");
Note that the filename is case senitive on some platforms so be careful that it matches exactly. Also, make sure you've set the file to Content / Copy if newer in the Properties window.
The alternative is to compile your assets into optimized binary XNB files using the XNA Game Studio Content Pipeline or the MonoGame Content Pipeline. This will give you better performance but carries extra development overhead.
I should also mention that when rendering your sprites as raw PNG files you should use BlendState.NonPremultiplied in the call to SpriteBatch.Begin for best results. I've been doing it this way in my games for a while and I'm pretty happy with the results.
MonoGame does not fully implement the content manager. Typically, you build the content separately, and import the built content files into your project. Then you can load them as usual.
To build the content files, you can use an XNA or MonoGame content builder such as this one. If you prefer, you can use command lines as part of your project's build process so that content is built automatically.
Make sure your Build Action is set to Content for the .png in question. Do this by right clicking the file and selecting properties.
I'm developing a Windows 8 Store App, I have this problem,
I want the user to add the videos from a file picker and i managed it,
the problem is I want to display the videos images in a GridView,
like snap shot of the video in a certain position, i tried the media element and it's not working
also an image and it doesn't make sense.
There might not be a pure C# solution to this problem. Perhaps SharpDX would let you do that, but I haven't tried and I don't know if it was done before. If you look at these two threads:
http://social.msdn.microsoft.com/Forums/fil-PH/wingameswithdirectx/thread/05731d4f-5b7f-4ed1-8e28-94604655139e
http://social.msdn.microsoft.com/Forums/en/wingameswithdirectx/thread/ffacd05c-6e9e-43bf-b691-99127240730c
-- you should see that there is a TransferVideoFrame method you can use to copy a frame from a video stream to a DirectX texture. The Media engine native C++ video playback sample shows how you can use it natively. If you search for TransferVideoFrame+SharpDX - you can find this sample that uses the SharpDX version of this method in C#. After you transfer that frame to a texture - you can either copy the contents of the texture to a WriteableBitmap using the Map and Unmap methods like here. You can also save it to a file either using BitmapEncoder a here or directly from the DirectX texture to a file using WIC or say SharpDX Toolkit as in here. You will probably want to build a cache of thumbnails to avoid having to process the videos every time you display the list, so saving to a file is something you should do anyway.
Your own solution that you quoted elsewhere that should work for at least some videos:
var thumb = await
storageFile.GetThumbnailAsync(
Windows.Storage.FileProperties.ThumbnailMode.PicturesView,
1000,
Windows.Storage.FileProperties.ThumbnailOptions.UseCurrentScale);
I suggest using GetThumbnailAsync(), which works just as well. You don't even need to get the video properties or anything like that. If the StorageFile is loaded, this should work for a normal video of any format.
Can the Collada (dae) file format be used for content, or is it strictly for reciprocity between 3D studios, etc? For example, I create a XNA game, could I create a loader and load it in for usage in my game? Would it be wise and legal to do this? Or can I only use it to transfer between Maya and 3D Max?
Collada is a perfectly acceptable format to use with XNA. Benjamin Nitschke has created an excellent tutorial on loading a Skinned Collada model with all of the necessary loader classes etc. on his website. The source code is at the end of the article along with some other useful links.
You can definitely use it as the main format for your game.
Many systems support directly loading COLLADA:
Second Life Mesh
Ogre
GLGE
three.js
and many more.
If you're using C#, there is a C# Collada library.