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

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.

Related

How to load images (jpg) in QML generated at runtime

my question is quite simple.
I have a Qt application with a Gui developed with QML.
My back-end side generates and saves jpg images in a folder called /images .
I am able to send from C++ to QML the strings holding the name of the images that I want to show. Sadly my QML Image object doesn't display anything.
It seems that if an image can be displayed only if it has been previously declared in the qml.qrc file.
Sadly, again, qrc files do not support wildcards yet!
https://bugreports.qt.io/browse/QTBUG-1400
Is there a workaround?
The name of the images are not fixed, they are generated with certain runtime values i.e. timestamp.
Thank you
By default it will search the image source in the qrc file. To make it go to the actual file system, prepend a file:/// to the path.

Can't load Image source in QML Image

This seems really basic but for some reason I can't get the image source to work in the ultra-simple QML app below.
FYI, I'm running Mac OS-X 10.9.5, Qt Creator 3.2.1 based on Qt 5.3.2.
import QtQuick 2.3
import QtQuick.Controls 1.2
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Test")
Image {
id: image1
x: 10
y: 10
width: 100
height: 100
source: "testImage.png"
}
}
I get the following error:
qrc:/main.qml:10:5: QML Image: Cannot open: qrc:/testImage.png
The application window is created but no image is displayed. I've also tried wrapping the image within a Rectangle but this doesn't help.
What am I doing wrong here?
The "testImage.png" is in the project directory and I've tried all sorts of ways to specify the image path using resources, absolute, relative, and even specifying the image source manually with the QML UI designer.
I'll also mention that to get Qt 5.3.2 to work I followed the modification suggested HERE.
Thanks.
I suppose that your qml file is in resources, so try place your testImage.png image in resources too. Recompile app, run it and check is image works properly.
All should be together. For example:
My code:
Image
{
source: "images/earth.png"
If I delete this image from resources, I'll get this error too, but image still in the correct place in file system.
When qml source placed in the resource, then all files, which loads from qml should be in resource too (Qt searchs this files in the resources, not in the file system).
If you are locating from local filesystem , get the file path and prefix "file:" as source = "file:/root/Desktop/Rathod.png"
If you are using qrc, make sure the image is added to your project. Just having it in your source directory may not be enough.
For example, my main.qml is located in a particular directory. I move my .png into the same directory. I then "Add Existing Files.." and add the .png to the project. My image has the following
source:"qrc:<same dir as main.qml>/image.png"
I had a similiar problem and solved it the following way:
Right click on your qml.qrc, then choose "open with" -> "Resource
Editor"
Once you are in the Resource Editor click on "Add missing file", there choose your image
Lastly open your qml file in the Design editor and click on the Image element, on the right side choose the path to the image
There can be two problems:
The image is corrupt, although the image was correctly displayed in all previews IconImage refuses to load it. Try to use another image that is known as work correctly
It seems that the Qt Image loader is very sensitive to the image format.
There is a resource cache problem. Try to delete qml_qmlcachea.qrc in your compiling folder and try it again
Try to close Shadow Build under Projects->Build Settings.

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.

SharpDX Content.Load<Texture2D>

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).

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... )

Resources