SharpDX Content.Load<Texture2D> - directx-11

I just installed SharpDX 2.5.0 into Visual Studio, and now there is one really curios and unexpected errror:
I wanted to start with Atari's 'Pong', so i drew a .bmp file with a ball, convertet it into a .dds file with
Easy2Convert BMP to DDS
added it to the Content, and tried to load it. So i added this line
ballTexture = Content.Load("Ball");
but it failed with the message AssetNotFoundException, the same with
ballTexture = Content.Load("Ball.dds");
and there are hardly no tutorials to find, neither did i find an useful answer...
Thats the full path to this picture:
H:\Programmieren\Pong\Pong\Content\Ball.dds
Looking forward to your answers, and please excuse my knowlegde, I was used to XNA, and it was much more easier...

In SharpDX.Toolkit content is loaded from a folder relative to the folder where your program is located. Also you should mark the texture with build action ToolkitTexture (open file properties in Visual Studio).
After build, the file should be copied to a path like this:
H:\Programmieren\Pong\Pong\bin\Debug\Content\Ball.tkb`
(the extension may be different - I don't remember exactly).
After this, you can load the asset by calling ballTexture = Content.Load(#"Content\Ball");
Alternatively, you can set the root path for content manager during initialization:
Content.RootDirectory = "Content";
...
//and load the textures with
ballTexture = Content.Load(#"Ball");
All this is demonstrated in SharpDX Toolkit samples (located in Samples\SharpDXToolkitSamples.sln).

Related

Visual studio Image folder in sub project

In one of my visual studio projects there are some sub directories each of them containing sub projects. In one such sub-project I have an Image folder containing an image. Now I am not being able to load that image doing something like this.
<img id="loading" src="~/Image/loader.gif" alt="loader">
When I hover on it in my dev tool it shows me the path like
http://localhost:62360/Image/loader
and the image is not found on that location. Any idea what can be done?
For everyone with problems like that
I highly recommend, if its a part of your project that shouldn't be replaced or be replaced, to use a resource file. Here is a small instrction how to do so.
You can now simply choose "~/resource/WhatIsThis.png" as URL (usually in the GUI the url can be choosen via dialog).
As said in documentation, it is important to know that the resource file will store the URL to your image, not the image itself. But that won't make a difference in this case.

Can't access files in my Mac APP Bundle

I am using wxwidget on my Mac OSX and just cant make my app access my resources directoy within my app bundle.
I have a file name image.bmp in my resources folder and accessing it through :
m_bitmap1 = new wxStaticBitmap( this, wxID_ANY, wxBitmap( wxT("Resources/image.bmp"), wxBITMAP_TYPE_ANY ), wxDefaultPosition, wxDefaultSize, 0 );
my app yell : "File not found error" on that file. I also tried ./Resource, or just image.bmp but nothing seems to work.
Looking into the app file I can see the file in there. but for some strange reason it seems to ignore it.
Any idea ?
By default wxOSX will only load PNG and JPEG bitmaps from the resources, so I advise you to convert your bitmap to PNG and use wxBITMAP_TYPE_PNG_RESOURCE in the ctor. You also need to remove the explicit "Resources/" as the path is looked up under this directory of your bundle automatically. I.e. the recommended solution is to use wxBitmap("image.png", wxBITMAP_TYPE_PNG_RESOURCE).
Notice that this works under Windows too, provided you embed your PNG into the resources using RCDATA type as explained in wxBITMAP_PNG() documentation. For the other platforms you would need to embed it directly into the program code, this is also explained in the same link.
Otherwise, i.e. if you really want to use BMP, you need to use wxStandardPaths::GetResourcesDir() to construct the full path to your bitmap explicitly.

dnn filepickeruploader control

Am developing a module for DotNetNuke 7. I want to be able to upload a thumbnail image for entries in a catalogue. Have managed place control in edit view of my module and upload and select files however when I build the project I get the following error:
C:\dnn\dotnetnuke\DesktopModules\EventCatalog\Edit.ascx.designer.cs(103,38,103,41): error CS0234: The type or namespace name 'Web' does not exist in the namespace 'DotNetNuke' (are you missing an assembly reference?)
Also I can't figure out how to get the selected file on the backend to save the url to database. When I enter the ID of the control VS recognizes it but intellisense doesn't provide any clues as possible options.
Can anyone tell me how to fix the above error and also if possible, point me towards a overview/tutorial for this control. Have done a fair amount of Googling but not found anything.
Well, to start, you probably need to add an assembly reference to DotNetNuke.Web to your project. Once that's there, it'll probably help with your lack of intellisense as well.
Looks like the main way you interact with the selected URL is via the FileID property. The control itself will manage saving the file to the selected FolderPath (which may or may not be something the user can change).
But, you're right, there aren't good resources for how to use the control. The best "tutorial" it probably looking through the DotNetNuke core code to see how the core uses the control.
The built in dnn upload control is specifically designed for uploading files to the dnn file system - but to be honest its pretty ugly to work with.
It makes a lot of assumptions about what you want to do with the file and as part of its process automatically registers new file in the dnn file system index.
Its also not really ideal for thumbnail uploads or any such fancy stuff - since it has no capability for file size management or scaling and cropping - its something that has been promised a couple of times but not eventuated to date.
On top of this is has a bit of a mind of its own when it comes to where it actually stores the uploaded file - which means you may be better off looking at a 3rd party uploader that you can control more easily.
FWIW - there is a full version of the telerik asyn upload library installed with every dnn install - you will need to setup it up manually but that is not that hard.
<dnn:DnnAsyncUpload></dnn:DnnAsyncUpload> is the markup basic structure and its functionally equivalent to <telerik:RadAsyncUpload></telerik:RadAsyncUpload>
Its documented here http://www.telerik.com/help/aspnet-ajax/asyncupload-overview.html
Having said all this if you do want to stick with dnn file picker - this code will let you find the file object that dnn uploaded the file too.
String thisURL = "";
String thisPHYSICAL = "";
Int32 itest001 = thisControl001.FileID;
if ( itest001 > 0 )
{
var thisFILE = (DotNetNuke.Services.FileSystem.FileInfo)FileManager.Instance.GetFile(itest001);
thisURL = FileManager.Instance.GetUrl(thisFILE );
thisPHYSICAL = thisURL.PhysicalPath;
}
thisURL will contain a url relative to your website domain
thisPHYSICAL will contain the physical location of the file on your server.

Reading JPG into BitmapData in ActionScript 3 (JPG is inside APK file)

I'm using Adobe AIR to make APK file for my Android phone. Inside the APK package there is a SWF file and in the same folder as the SWF file there is a subfolder named "images", which contains image.jpg.
I'm trying to read that image.jpg into the program at runtime but can't get the location of it (the program doesn't seem to find it.
Here's what I'm trying:
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("images/image.jpg"));
while (bitmapData==null) {} //wait until loaded
return bitmapData;
The onComplete-function puts sets the bitmapData field. However, the COMPLETE event never happens so the while loop never exists.
I have also tried:
loader.load(new URLRequest("/images/image.jpg"));
loader.load(new URLRequest("app:/images/image.jpg"));
loader.load(new URLRequest("app-storage:/images/image.jpg"));
loader.load(new URLRequest("file:/images/image.jpg"));
None of it works.
I can't get this to work even when trying without the APK file, when only running the SWF file that is generated (the images subfolder is in the same folder as the SWF file).
I can't embed the JPG into the SWF file itself because I need to have a lot of image files and Flash CS6 runs out of memory when making such a big SWF file (reading the images externally would also mean a whole lot less compilation time).
Any ideas? How can I get put the external JPG file into BitmapData? Remember that the image is not outside of the APK file, it is packaged inside it.
Note: I'll also export the thing into a iOS ipa package later so it have to work there as well.
Edit because I can't self-answer due to my reputation.
Strille made me realize that the ActionScript Virtual Machine is single-threaded.
So it's impossible to make a thread sleep (wait) for an image being loaded. Instead I have to sigh rewrite a lot of code so that things are halted and continues when the onComplete function is called.
This thing that I tried before actually works but couldn't complete due to the while loop:
loader.load(new URLRequest("app:/images/image.jpg"));
If I remember correctly, you should be able to do it like this:
loader.load(new URLRequest(new File("app:/images/image.jpg").url));
Since we're using the File class, the above will not run in the Flash Player, just on iOS or Android.
From my experience there are two practical methods to load assets from a running Android APP using AIR
using URLLoader and .url property of the File instance
using FileStream (which receives a File instance)
Adding to project
You can package the files inside the APK using
the same technique as packaging ICONS, inside the .xml descriptor file for your app.
And make sure you add those to your IDE in the Android section (applies to IntelliJ and Flash Builder) "Files and folders to package"
- add the path to your wanted assets folder, and give it a relative name alias.
Elaboration
The assets themselves are placed (when the APP is installed),
inside the ''applicationDirectory'' which is available for AIR,
Yet since newer Android OS's, and Flash player security issues,
it is not possible to access those assets via the nativePath,
only the 'url' property of the File instance.
Best Practice
Use URLLoader and .url property of the File instance,
as it is also Asynchronous by nature and can resolve PNG / JPG files
using native decoder instead of having to do this manually
reading a FileStream (which returns a a ByteArray)
var f:File = File.applicationDirectory.resolvePath('images/myimage.png');
loader.load(new URLRequest(f.url));
and,
If I'm missing more ways, please let know... )

How do I load an image using SDL and Xcode on OS X 10.5?

Edit: After using a bmp at toastie's suggestion, I'm still having problems loading the image:
I'm using SDL and OpenGL with Xcode and I'm trying to load an image to use as a texture on a cube. The image is a 256x256 RBG jpeg. The image is in the same directory as all of my source code, and it's under the Resources folder in the Xcode project. The file is named texture.bmp
if (textureSurface = SDL_LoadBMP("texture.bmp"))
{
// ...
}
else printf("%s", SDL_GetError());
I keep running it and getting the console error: Couldn't open texture.bmp
What is the path, or proper syntax for loading a file under these conditions?
SDL_LoadBMP only loads BMP files as its name would suggest :)
You will need another library to load other image formats.
Try SDL_image:
http://www.libsdl.org/projects/SDL_image/
or DevIL:
http://openil.sourceforge.net/
Or roll your own loader:
http://www.libpng.org/pub/png/libpng.html
Found the answer here. Essentially the image path is relative to the application being run, so I had to move the image or make the path relative to the debug build.
I don't have Xcode in front of me, but I think if you right/option click on the file in your resources listing to get at the preferences for the file you can set it to be relative to the project, containing directory, etc.

Resources