[java] URGENT: Get a Image shown on Canvas JNI

Started by
9 comments, last by biowarrior 18 years, 4 months ago
Here's my problem: I have a Canvas which is rendered at JNI and I would like to get the Image object who represent the picture shown on it. I overload the paint(Graphics g) method in my Canvas, which is a native method (I could do it at any other method). At Java: public native void paint(Graphics g); At C++: JNIEXPORT void JNICALL Java_Bitmap_paint( JNIEnv* env, jobject canvas, // equivale ao this jobject graphics ) { // desenho no Canvas usando JNI, API do Windows e outras APIs. } Now, the the Canvas is draw by JNI (C++ and GDI/DirectX) without any problem, but HOW CAN I ACCESS THIS IMAGEM FROM JAVA? I need to manipulate this Canvas Image on Java, not at JNI level! Please, anyone can help me? Thanks!
guilherme
Advertisement
Hi, brazillian fellow. I suggest translating your code's comments from portuguese to english. Even if they're not important to answer your question ;)

I guess this thread will be helpful to you.

I'm not sure if a jimage type exists for JNI, but perhaps you can always return data as an array, and build it up as a Java instance in the Java environment. Just guessing here.

Son Of Cain

a.k.a javabeats at yahoo.ca
Man, after I post the code I noticed that my coments were in portuguese lol

Son of Cain, I already saw that thread.
- This is what I already have: a JNI drawing on Canvas;
- But what I really want: Get the image object which represent the Canvas draw saurface.

I search on Google through all possibles words, foruns, ... neither Sun has a good documentation about JNI drawing and Image manipulation.

On JNI exist only jobject, but I can get other classes through bizarres manipulations, I got a code about JTwain which do that, but I tried to adapt that code to my use and the C/C++ start to crash, crash and crash my VM.

It could be easier to:
- Get the image drew on Canvas surface (because I already have it, that thread you send has the code :D) and manipulate it;
Than:
- Get a bitmap data through loops and pointers, fill an array of JAVA bytes at JNI level and create a object or array to send back to Java;

But I guess someone already did it on earth before me :)

But thanks for help!
guilherme
Nobody knows how to get the image displayed on Canvas?

Hey guys, help me!
guilherme
Hey dude, it's not something easy, you know that ;)

If you really have to use JNI for that - I mean, to draw stuff, because the GL bindings nowadays are pretty fast - consider wrapping the C++ data for a java recognizable type, like jobject or a jarray.

I've seen some JNI code for OpenGL bindings that used just that, although the need was not the same as yours.

Son Of Cain
a.k.a javabeats at yahoo.ca
"consider wrapping the C++ data for a java recognizable type, like jobject or a jarray."

I tried that, Son of Cain, but I'm having problems with that, cause my Win32API/C++ is not that good as was in the past :D. For me, would be easier to get the Canvas Image.

But do you know where could I find a code that get the DIB-16bit palettized data (already in memory) and put it on an array, not necessary a java array? I'm guess that I'm fail at some detail I'm not paing to much atention.

Any way, thanks for all.
guilherme

I would just render directly to the canvas from native. Get the hwnd pointer through JNI, and initialize DirectX with it and start rendering directly to the canvas.
Passing image data back to Java and letting Java render the image to the canvas doesn't sound like a good idea. It would probably be quicker to use the Java OpenGL wrappers than passing the image data back to Java.

Check out the jawt.h file in the 'include ' folder under the jdk install directory.

Hope that helps.
-x-
I don't think that's what he want - from his thread title, he wants to manage an Image of the Canvas (might be the entire Canvas or a portion of it) on the "java-side" of things

Indeed, studing the jawt lib is the only hope you have, I think ^_^

Sorry for not being able to help, fellow.

Son Of Cain
a.k.a javabeats at yahoo.ca
"Passing image data back to Java and letting Java render the image to the canvas doesn't sound like a good idea. It would probably be quicker to use the Java OpenGL wrappers than passing the image data back to Java."

Good, except by the fact that my clients asked me for a Java program, not a C++ program :-) If I do all image manipulation in DirectX, why would I use Java?
guilherme
But the main reason is that I have a great team of Java programmers, some of them better in Java than me, but I'm the only one who has experience in C/C++ and DirectX/Win32 development. If I move the work to C/C++, I would be wasting those great programmers and overload my head with work!!! :-)
guilherme

This topic is closed to new replies.

Advertisement