@daniewang Once you saved the image to the file system, load the sprite like you would normally do, but use the absolute path (named pngPath on the previous code). Cocos2d-x will load it like any other image.
You may have noticed notice notifyImagePicked([saveName UTF8String], [identifier UTF8String]); : I implement this function in the C++ part, and send a notification that the C++ uses to react to the new image. Note: the identifier is not needed, it’s an easy way for me to identify what they are linked to. You may want to use fullPath instead of saveName if you want to directly use that to load your sprite (on the other hand, if you save the path, use a relative path to save space, and reconstruct full path at runtime).
@ZippoLag since then, I open-sourced my framework. This feature is part of FenneX, take a look: https://github.com/FenneX/FenneX The C++ usage is very simple : call pickImage and add an observer for the “ImagePicked” notification.
There is no usage example yet, but I could do one. I need to get started on samples.
@Fradow Have you tested it on Windows? it seem that android.mk find relies on gnu find, when trying to build on windows (with gnu find) the following errors are presented…
In file included from jni/…/…/Classes/FenneX/Core/GesturesHandling/GenericReco
gnizer.cpp:25:
jni/…/…/Classes/FenneX/Core/GesturesHandling/GenericRecognizer.h:28:10: fatal
error:
‘Logs.h’ file not found #include “Logs.h”
^
In file included from jni/…/…/Classes/FenneX/Core/CCBIntegration/CustomNode.cp
p:25:
In file included from jni/…/…/Classes/FenneX/Core/CCBIntegration/CustomNode.h:
30:
jni/…/…/Classes/FenneX/Core/CCBIntegration/CustomBaseNode.h:30:10: fatal error
:
‘FenneXMacros.h’ file not found #include “FenneXMacros.h”
^
In file included from jni/…/…/Classes/FenneX/Core/CCBIntegration/FenneXCCBLoad
er.cpp:27:
jni/…/…/Classes/FenneX/Core/CCBIntegration/FenneXCCBLoader.h:29:10: fatal erro
r:
‘FenneXMacros.h’ file not found #include “FenneXMacros.h”
^
In file included from jni/…/…/Classes/FenneX/Core/CCBIntegration/CustomBaseNod
e.cpp:25:
jni/…/…/Classes/FenneX/Core/CCBIntegration/CustomBaseNode.h:30:10: fatal error
:
‘FenneXMacros.h’ file not found #include “FenneXMacros.h”
^
In file included from jni/…/…/Classes/FenneX/Core/CCBIntegration/CustomSprite.
cpp:25:
In file included from jni/…/…/Classes/FenneX/Core/CCBIntegration/CustomSprite.
h:30:
jni/…/…/Classes/FenneX/Core/CCBIntegration/CustomBaseNode.h:30:10: fatal error
:
‘FenneXMacros.h’ file not found #include “FenneXMacros.h”
^
@viran No, it’s not tested on Windows, and the Android.mk definitely won’t work on Windows, because it relies on find command.
You need to replace it by dir command with the appropriate parameters, or manually list all the files (like cocos2d-x does). Unfortunately, I don’t work on Windows, so I can’t help you.
Since your library is version 2 compatible, and I dont have the time to port it all,
If all I need is image picker from the Gallery/Camera, can I do it with a selected few files? Which files?
take projects / Classes / FenneX / NativeWrappers / ImagePickerWrapper.h
take projects / proj.ios / ImagePicker.h and .mm
take projects / proj.android / jni / ImagePickerWrapper.cpp
take projects / proj.android / src / com / fennex / modules / ImagePicker.java
add ImagePickerWrapper.cpp to your Android.mk
in ImagePicker.java, you need to replace NativeUtility.getMainActivity by your main Activity. Your Activity must forward onActivityResult to ImagePicker
there may be a few shorteners use, you will find the definitions in projects / Classes / FenneX / Core / Utility / Shorteners.h
don’t forget about the permissions (Android) and frameworks (iOS). I don’t remember the specific ones.
resolve any other problem. It shouldn’t be very hard as there are very few dependencies between the wrappers and the rest ofthe code.
You are in luck, following your question, I decided to start the samples with that feature (it’s a recurring question in cocos2d-x forum to be honest). Have a look: https://github.com/FenneX/FenneXTestProject The last commit from October 19th is the most interesting for you. It is for V3.2, but FenneX interface didn’t change yet from V2.X
What are you struggling with? An error message, another problem?
@obsothoth Currently, FenneX use Gradle version 2.2.1. The TestProject might be outdated by now, I didn’t update it in a while. It should be trivial to update to last Gradle version.
Thanks for the quick reply! New to Gradle here so bear with me please.
So I managed to change the Gradle version in the build.gradle file, but it seems there is a module missing somewhere, any ideas on how I could fix it?
What went wrong:
Execution failed for task ‘:ndkBuild’.
A problem occurred starting process ‘command ‘ndk-build.cmd’’
Try:
Run with --info or --debug option to get more log output.
Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:ndkBuil
d’.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExec
uter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.exec
ute(SkipUpToDateTaskExecuter.java:64)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execut
e(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecu
ter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter
.execute(SkipTaskWithNoActionsExecuter.java:52)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execut
e(SkipOnlyIfTaskExecuter.java:53)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter
.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailur
e(AbstractTask.java:305)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.executeTask(AbstractTaskPlanExecutor.java:79)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.processTask(AbstractTaskPlanExecutor.java:63)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.run(AbstractTaskPlanExecutor.java:51)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(Defaul
tTaskPlanExecutor.java:23)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(Defau
ltTaskGraphExecuter.java:88)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTask
ExecutionAction.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
r.java:62)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExec
uter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecu
ter.java:68)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildEx
ecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
r.java:62)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
r.java:55)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(Default
GradleLauncher.java:149)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradle
Launcher.java:106)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLaun
cher.java:86)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildCon
troller.run(InProcessBuildActionExecuter.java:80)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.jav
a:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.jav
a:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:36)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:26)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.jav
a:171)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:237)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:210)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRunti
meValidationAction.java:35)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRunti
meValidationAction.java:24)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:206)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:169)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBoots
trap.java:54)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.j
ava:35)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: org.gradle.process.internal.ExecException: A problem occurred startin
g process ‘command ‘ndk-build.cmd’’
at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(Default
ExecHandle.java:196)
at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandl
e.java:325)
at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.jav
a:83)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecut
orImpl$1.run(DefaultExecutorFactory.java:64)
Caused by: net.rubygrapefruit.platform.NativeException: Could not start ‘ndk-bui
ld.cmd’
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(Def
aultProcessLauncher.java:27)
at net.rubygrapefruit.platform.internal.WindowsProcessLauncher.start(Win
dowsProcessLauncher.java:22)
at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(Wra
pperProcessLauncher.java:36)
at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.jav
a:65)
… 1 more
Caused by: java.io.IOException: Cannot run program “ndk-build.cmd” (in directory
“C:\Users\V3\Desktop\stuff\code\not mine\FenneXTestProject-master\proj.android”
): CreateProcess error=2, The system cannot find the file specified
at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(Def
aultProcessLauncher.java:25)
… 4 more
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find th
e file specified
… 5 more
The problem is that it can’t find ndk-build.cmd. I am not sure it’s even the correct name for Windows, some tutorials refer to ndk-build without the “.cmd” extension.
This project does not, at the moment, properly support Windows building (as I don’t have any Windows box to test on), so there are a few other things that probably won’t work off the box. The one I’m thinking about is the proj.android/jni/Android.mk file, which uses Unix-specific command lines. You need to change it to use Windows-specific command lines. It was talked about here Is there are way to create android.mk automatically and here Avoiding absolute paths including headers