Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <android/bitmap.h>
  2. #include <jni.h>
  3.  
  4.  
  5. template< class T, class TCpp >
  6. class JavaArrayAccessor
  7. {
  8. public:
  9. JavaArrayAccessor(JNIEnv* env, T array) :
  10. env(env),
  11. array(array),
  12. data(reinterpret_cast< TCpp* >(env->GetPrimitiveArrayCritical(array, NULL))) // never returns NULL
  13. {}
  14.  
  15. ~JavaArrayAccessor()
  16. {
  17. env->ReleasePrimitiveArrayCritical(array, data, 0);
  18. }
  19.  
  20. TCpp* getData()
  21. {
  22. return data;
  23. }
  24.  
  25. private:
  26. JNIEnv* env;
  27. T array;
  28. TCpp* data;
  29. };
  30.  
  31.  
  32. class AndroidBitmapAccessor
  33. {
  34. public:
  35. AndroidBitmapAccessor(JNIEnv* env, jobject bitmap):
  36. env(env),
  37. bitmap(bitmap),
  38. data(NULL)
  39. {
  40. int rv = AndroidBitmap_lockPixels(env, bitmap, reinterpret_cast< void** >(&data));
  41. }
  42.  
  43. ~AndroidBitmapAccessor()
  44. {
  45. if(data)
  46. {
  47. AndroidBitmap_unlockPixels(env, bitmap);
  48. }
  49. }
  50.  
  51. unsigned char *getData()
  52. {
  53. return data;
  54. }
  55.  
  56. private:
  57. JNIEnv* env;
  58. jobject bitmap;
  59. unsigned char *data;
  60. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement