My C + + test code as follows:
# Include "com_cn_SKiaView.h"
# Include "SkCanvas.h"
# Include "SkPaint.h"
# Include "SkGraphics.h"
# Include "SkColor.h"
# Include "SkTypes.h"
# Include "GraphicsJNI.h"
# Include
JNIEXPORT jint JNICALL Java_com_cn_SKiaView_renderHello
(JNIEnv * env, jobject thizz, jobject canvas)
{
SkCanvas * canv = GraphicsJNI :: getNativeCanvas (env, canvas);
if (! canv)
{
LOGD ("canv is NULL \ n!");
return 0;
}
SkPaint paint;
LOGD ("! SetColor WHITE \ n");
paint.setColor (SK_ColorWHITE);
paint.setTextSize (20);
canv-> drawText ("Hello", 5, 100, 100, pen);
canv-> drawLine (0,0, 100,100, paint);
LOGD ("Hello LIB \ n!");
return 1;
}
Under my Java code to call the following:
public class SKiaView extends View
{
private static final String TAG = "SKIAJNI";
static
{
System.loadLibrary ("skiajni");
}
public native int renderHello (Canvas canvas);
public SKiaView (Context context)
{
super (context);
}
@ Override
public void onDraw (Canvas canvas)
{
super.onDraw (canvas);
Log.d (TAG, "before renderHello");
renderHello (canvas);
Log.d (TAG, "after renderHello");
}
}
Why canv-> drawLine () can draw lines, canv-> drawText () do not show the text?
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
canv-> drawText ("Hello", 5, 100, 100, pen);
Need to set brush
Paint pen = new Paint ();
pen.setColor (Color.Red);
Reply:
Reply:
Oh, sorry, I'm sorry when I copied the code, forgot to put pen to paint a modification.
canv-> drawText ("Hello", 5, 100, 100, paint);
Anyway, still can not display text, but with the Canvas class drawText Android indeed can be displayed. Really strange, maybe it is something else.
Reply:
Are you sure you can be transferred to the following function?
Reply:
Strange how your drawText took five parameters? JAVA layer transfer as long as four ah! You did not create or specify the font size of it! ! !
Reply:
How to build C + + compiler environment? There is no point in this regard? My C ambient no problem!
Reply:
Hello, JAVA layer is only four parameters, but JAVA is the last tune of SKIA C + + graphics library functions are five parameters.
My argument is that the five way through JNI to call C + + layer.
Reply:
Hello, you might want to go look NDK environment, which is used to quickly through your C code to generate dynamic libraries. NDK now but still just getting started, there is no good visual IDE, need to use a lot of LINUX knowledge compiled under.
Reply:
Confirmation can be transferred to the following function LOG .. and can print out the log.
Simulator and the real machine only to draw a line, but did not draw the text on the Internet to see someone else can draw text, do not know why. Did I downloaded the source code SKIA interface and the actual use of the simulator SKIA library interface is different?
Reply:
canv-> drawText ("Hello", 5, 100, 100, pen); java in this way is four or six parameters, the landlord more than a C + + that argument is it? What's the use?
canv-> drawLine (0,0, 100,100, paint); java is five parameters, where C + + call parameters or change how powerless 5? Trouble landlord
Reply:
canv-> drawLine (0,0, 100,100, paint); first four parameters are the start and end points of x1, y1, x2, y2 are the coordinates of the last parameter is not changed in SkCanvas Paint class, because it is painted.. line.
Reply:
I have solved this problem.
Share what reason, I hope everyone in the future be careful.
The reason is because I am at compile time,
Include the path skia Android.mk file contains the source code from different places.
One is derived from the use git to download android2.2 (froyo) source code in skia.
Another is from svn https://skia.googlecode.com/svn/trunk
My Android.mk file contents (header files from svn https://skia.googlecode.com/svn/trunk).
LOCAL_CXXFLAGS: =
LOCAL_C_INCLUDES: = \
E :/ NDKr5/sources/SKIA/include/core \
E :/ NDKr5/sources/SKIA/include/config \
E :/ NDKr5/sources/android/frameworks/base/include \
E :/ NDKr5/sources/android/system/core/include \
E :/ NDKr5/sources/android/frameworks/base/core/jni/android/graphics \
E :/ NDKr5/sources/android/dalvik/libnativehelper/include
Into: (header files directory skia android2.2 (froyo) in the source code.)
E :/ NDKr5/sources/android/external/skia/include/core \
E :/ NDKr5/sources/android/external/skia/include/config \
E :/ NDKr5/sources/android/frameworks/base/include \
E :/ NDKr5/sources/android/system/core/include \
E :/ NDKr5/sources/android/frameworks/base/core/jni/android/graphics \
E :/ NDKr5/sources/android/dalvik/libnativehelper/include
On it.
Has been verified in the simulator and the real machine.
Summary: The reason causing this problem should be at compile time, mk file with the current compiler options used on the simulator or a real machine inconsistent SKIA dynamic library version of the source code is compiled, resulting compiled interface so dynamic library calls. and SKIA dynamic library interface emulator or on a real machine environment caused by inconsistencies.
Reply:
Hello, as adjusted under a layer of SKIA Java library code also need to bring a string length parameter canv-> drawText ("Hello", 5, 100, 100, paint);. Place of "Hello" is the length of 5 , JAVA only need four parameters, probably because the Canvas class encapsulates, which calculates the length of the string, if you follow up on what drawText function of this class you will find Native local function call is the last five parameters Another string length will be calculated in the class package.
Reply:
Under svn https://skia.googlecode.com/svn/trunk have something to refer to? !
Reply:
Will the landlord, how drawText display English ah?
Reply:
mark it, recently I have encountered this problem. See if you can help solve
Reply:
Brother, you run the code I used 4.03, there is a text ah, all drawn out
Reply:
Did not find the font, the font settings android before writing, font
No comments:
Post a Comment