Unable to find PixelFormat Enum for Xamarin Android











up vote
3
down vote

favorite












I have the below code where i am creating a ImageReader instance in xamarin android, how to change Image Format from ImageFormatType.Rgb565 to PixelFormat.RGBA_8888



i am unable to find the Library or a Enum class for it.



mImageReader = ImageReader.NewInstance(windowWidth, windowHeight, ImageFormatType.Rgb565, 2)









share|improve this question




























    up vote
    3
    down vote

    favorite












    I have the below code where i am creating a ImageReader instance in xamarin android, how to change Image Format from ImageFormatType.Rgb565 to PixelFormat.RGBA_8888



    i am unable to find the Library or a Enum class for it.



    mImageReader = ImageReader.NewInstance(windowWidth, windowHeight, ImageFormatType.Rgb565, 2)









    share|improve this question


























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I have the below code where i am creating a ImageReader instance in xamarin android, how to change Image Format from ImageFormatType.Rgb565 to PixelFormat.RGBA_8888



      i am unable to find the Library or a Enum class for it.



      mImageReader = ImageReader.NewInstance(windowWidth, windowHeight, ImageFormatType.Rgb565, 2)









      share|improve this question















      I have the below code where i am creating a ImageReader instance in xamarin android, how to change Image Format from ImageFormatType.Rgb565 to PixelFormat.RGBA_8888



      i am unable to find the Library or a Enum class for it.



      mImageReader = ImageReader.NewInstance(windowWidth, windowHeight, ImageFormatType.Rgb565, 2)






      android xamarin bitmap xamarin.android image-reader






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 6:40

























      asked Nov 11 at 21:54









      VINNUSAURUS

      1941414




      1941414
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          You need to pass an int value of 3 (Android.Graphics.Format.Rgb888) to ImageReader.NewInstance, but currently you can not.



          That is a bug/issue in Xamarin.Android auto-generation API process as they do not create a overload that accepts an Android.Graphics.Format enum, or just a plain int as the Java API does.



          You can do this the same way you would do it in Java via Xamarin.Android's binding to Android.Runtime.JNIEnv or Java.Lang.Reflect



          Example using JNI:



          Note: Using JNI requires that the assembly be allowed to use "unsafe" code ( on the plus side, JNI is faster execution than using reflection...)



          public static class ImageReaderEx
          {
          public unsafe static ImageReader NewInstance(int width, int height, Android.Graphics.Format format, int maxImages)
          {
          JniArgumentValue* ptr = stackalloc JniArgumentValue[4];
          *ptr = new JniArgumentValue(width);
          ptr[1] = new JniArgumentValue(height);
          ptr[2] = new JniArgumentValue((int)format);
          ptr[3] = new JniArgumentValue(maxImages);
          JniPeerMembers _members = new XAPeerMembers("android/media/ImageReader", typeof(ImageReader));
          return Java.Lang.Object.GetObject<ImageReader>(_members.StaticMethods.InvokeObjectMethod("newInstance.(IIII)Landroid/media/ImageReader;", ptr).Handle, JniHandleOwnership.TransferLocalRef);
          }

          public unsafe static ImageReader NewInstance(int width, int height, int format, int maxImages)
          {
          JniArgumentValue* ptr = stackalloc JniArgumentValue[4];
          *ptr = new JniArgumentValue(width);
          ptr[1] = new JniArgumentValue(height);
          ptr[2] = new JniArgumentValue(format);
          ptr[3] = new JniArgumentValue(maxImages);
          JniPeerMembers _members = new XAPeerMembers("android/media/ImageReader", typeof(ImageReader));
          return Java.Lang.Object.GetObject<ImageReader>(_members.StaticMethods.InvokeObjectMethod("newInstance.(IIII)Landroid/media/ImageReader;", ptr).Handle, JniHandleOwnership.TransferLocalRef);
          }
          }


          Usage:



          var imageReader = ImageReaderEx.NewInstance(1, 1, 3, 1);


          or



          var ImageReader = ImageReaderEx.NewInstance(1, 1, Android.Graphics.Format.Rgb888, 1);





          share|improve this answer























          • which jar file I should use for binding? and where to find them?
            – VINNUSAURUS
            Nov 12 at 5:46










          • No jar file needed.
            – Cheesebaron
            Nov 12 at 6:48










          • @VINNUSAURUS No jar file, just via Java reflection or JNI, if you do not know how, I can help you with code later (not at my PC)
            – SushiHangover
            Nov 12 at 7:35












          • can u show me how, because I cannot understand it, I am new to this, i will wait for the code.
            – VINNUSAURUS
            Nov 12 at 7:39












          • @VINNUSAURUS I added an example
            – SushiHangover
            Nov 12 at 8:19


















          up vote
          0
          down vote













          In Xamarin, its Format.Rgba8888 (lower case). the doc is here






          share|improve this answer





















          • That will not work as ImageReader.NewInstance does not accept a Format enum as a parameter, it is an issue in the auto-generated API bindings...
            – SushiHangover
            Nov 11 at 22:30











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253632%2funable-to-find-pixelformat-enum-for-xamarin-android%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          You need to pass an int value of 3 (Android.Graphics.Format.Rgb888) to ImageReader.NewInstance, but currently you can not.



          That is a bug/issue in Xamarin.Android auto-generation API process as they do not create a overload that accepts an Android.Graphics.Format enum, or just a plain int as the Java API does.



          You can do this the same way you would do it in Java via Xamarin.Android's binding to Android.Runtime.JNIEnv or Java.Lang.Reflect



          Example using JNI:



          Note: Using JNI requires that the assembly be allowed to use "unsafe" code ( on the plus side, JNI is faster execution than using reflection...)



          public static class ImageReaderEx
          {
          public unsafe static ImageReader NewInstance(int width, int height, Android.Graphics.Format format, int maxImages)
          {
          JniArgumentValue* ptr = stackalloc JniArgumentValue[4];
          *ptr = new JniArgumentValue(width);
          ptr[1] = new JniArgumentValue(height);
          ptr[2] = new JniArgumentValue((int)format);
          ptr[3] = new JniArgumentValue(maxImages);
          JniPeerMembers _members = new XAPeerMembers("android/media/ImageReader", typeof(ImageReader));
          return Java.Lang.Object.GetObject<ImageReader>(_members.StaticMethods.InvokeObjectMethod("newInstance.(IIII)Landroid/media/ImageReader;", ptr).Handle, JniHandleOwnership.TransferLocalRef);
          }

          public unsafe static ImageReader NewInstance(int width, int height, int format, int maxImages)
          {
          JniArgumentValue* ptr = stackalloc JniArgumentValue[4];
          *ptr = new JniArgumentValue(width);
          ptr[1] = new JniArgumentValue(height);
          ptr[2] = new JniArgumentValue(format);
          ptr[3] = new JniArgumentValue(maxImages);
          JniPeerMembers _members = new XAPeerMembers("android/media/ImageReader", typeof(ImageReader));
          return Java.Lang.Object.GetObject<ImageReader>(_members.StaticMethods.InvokeObjectMethod("newInstance.(IIII)Landroid/media/ImageReader;", ptr).Handle, JniHandleOwnership.TransferLocalRef);
          }
          }


          Usage:



          var imageReader = ImageReaderEx.NewInstance(1, 1, 3, 1);


          or



          var ImageReader = ImageReaderEx.NewInstance(1, 1, Android.Graphics.Format.Rgb888, 1);





          share|improve this answer























          • which jar file I should use for binding? and where to find them?
            – VINNUSAURUS
            Nov 12 at 5:46










          • No jar file needed.
            – Cheesebaron
            Nov 12 at 6:48










          • @VINNUSAURUS No jar file, just via Java reflection or JNI, if you do not know how, I can help you with code later (not at my PC)
            – SushiHangover
            Nov 12 at 7:35












          • can u show me how, because I cannot understand it, I am new to this, i will wait for the code.
            – VINNUSAURUS
            Nov 12 at 7:39












          • @VINNUSAURUS I added an example
            – SushiHangover
            Nov 12 at 8:19















          up vote
          0
          down vote



          accepted










          You need to pass an int value of 3 (Android.Graphics.Format.Rgb888) to ImageReader.NewInstance, but currently you can not.



          That is a bug/issue in Xamarin.Android auto-generation API process as they do not create a overload that accepts an Android.Graphics.Format enum, or just a plain int as the Java API does.



          You can do this the same way you would do it in Java via Xamarin.Android's binding to Android.Runtime.JNIEnv or Java.Lang.Reflect



          Example using JNI:



          Note: Using JNI requires that the assembly be allowed to use "unsafe" code ( on the plus side, JNI is faster execution than using reflection...)



          public static class ImageReaderEx
          {
          public unsafe static ImageReader NewInstance(int width, int height, Android.Graphics.Format format, int maxImages)
          {
          JniArgumentValue* ptr = stackalloc JniArgumentValue[4];
          *ptr = new JniArgumentValue(width);
          ptr[1] = new JniArgumentValue(height);
          ptr[2] = new JniArgumentValue((int)format);
          ptr[3] = new JniArgumentValue(maxImages);
          JniPeerMembers _members = new XAPeerMembers("android/media/ImageReader", typeof(ImageReader));
          return Java.Lang.Object.GetObject<ImageReader>(_members.StaticMethods.InvokeObjectMethod("newInstance.(IIII)Landroid/media/ImageReader;", ptr).Handle, JniHandleOwnership.TransferLocalRef);
          }

          public unsafe static ImageReader NewInstance(int width, int height, int format, int maxImages)
          {
          JniArgumentValue* ptr = stackalloc JniArgumentValue[4];
          *ptr = new JniArgumentValue(width);
          ptr[1] = new JniArgumentValue(height);
          ptr[2] = new JniArgumentValue(format);
          ptr[3] = new JniArgumentValue(maxImages);
          JniPeerMembers _members = new XAPeerMembers("android/media/ImageReader", typeof(ImageReader));
          return Java.Lang.Object.GetObject<ImageReader>(_members.StaticMethods.InvokeObjectMethod("newInstance.(IIII)Landroid/media/ImageReader;", ptr).Handle, JniHandleOwnership.TransferLocalRef);
          }
          }


          Usage:



          var imageReader = ImageReaderEx.NewInstance(1, 1, 3, 1);


          or



          var ImageReader = ImageReaderEx.NewInstance(1, 1, Android.Graphics.Format.Rgb888, 1);





          share|improve this answer























          • which jar file I should use for binding? and where to find them?
            – VINNUSAURUS
            Nov 12 at 5:46










          • No jar file needed.
            – Cheesebaron
            Nov 12 at 6:48










          • @VINNUSAURUS No jar file, just via Java reflection or JNI, if you do not know how, I can help you with code later (not at my PC)
            – SushiHangover
            Nov 12 at 7:35












          • can u show me how, because I cannot understand it, I am new to this, i will wait for the code.
            – VINNUSAURUS
            Nov 12 at 7:39












          • @VINNUSAURUS I added an example
            – SushiHangover
            Nov 12 at 8:19













          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          You need to pass an int value of 3 (Android.Graphics.Format.Rgb888) to ImageReader.NewInstance, but currently you can not.



          That is a bug/issue in Xamarin.Android auto-generation API process as they do not create a overload that accepts an Android.Graphics.Format enum, or just a plain int as the Java API does.



          You can do this the same way you would do it in Java via Xamarin.Android's binding to Android.Runtime.JNIEnv or Java.Lang.Reflect



          Example using JNI:



          Note: Using JNI requires that the assembly be allowed to use "unsafe" code ( on the plus side, JNI is faster execution than using reflection...)



          public static class ImageReaderEx
          {
          public unsafe static ImageReader NewInstance(int width, int height, Android.Graphics.Format format, int maxImages)
          {
          JniArgumentValue* ptr = stackalloc JniArgumentValue[4];
          *ptr = new JniArgumentValue(width);
          ptr[1] = new JniArgumentValue(height);
          ptr[2] = new JniArgumentValue((int)format);
          ptr[3] = new JniArgumentValue(maxImages);
          JniPeerMembers _members = new XAPeerMembers("android/media/ImageReader", typeof(ImageReader));
          return Java.Lang.Object.GetObject<ImageReader>(_members.StaticMethods.InvokeObjectMethod("newInstance.(IIII)Landroid/media/ImageReader;", ptr).Handle, JniHandleOwnership.TransferLocalRef);
          }

          public unsafe static ImageReader NewInstance(int width, int height, int format, int maxImages)
          {
          JniArgumentValue* ptr = stackalloc JniArgumentValue[4];
          *ptr = new JniArgumentValue(width);
          ptr[1] = new JniArgumentValue(height);
          ptr[2] = new JniArgumentValue(format);
          ptr[3] = new JniArgumentValue(maxImages);
          JniPeerMembers _members = new XAPeerMembers("android/media/ImageReader", typeof(ImageReader));
          return Java.Lang.Object.GetObject<ImageReader>(_members.StaticMethods.InvokeObjectMethod("newInstance.(IIII)Landroid/media/ImageReader;", ptr).Handle, JniHandleOwnership.TransferLocalRef);
          }
          }


          Usage:



          var imageReader = ImageReaderEx.NewInstance(1, 1, 3, 1);


          or



          var ImageReader = ImageReaderEx.NewInstance(1, 1, Android.Graphics.Format.Rgb888, 1);





          share|improve this answer














          You need to pass an int value of 3 (Android.Graphics.Format.Rgb888) to ImageReader.NewInstance, but currently you can not.



          That is a bug/issue in Xamarin.Android auto-generation API process as they do not create a overload that accepts an Android.Graphics.Format enum, or just a plain int as the Java API does.



          You can do this the same way you would do it in Java via Xamarin.Android's binding to Android.Runtime.JNIEnv or Java.Lang.Reflect



          Example using JNI:



          Note: Using JNI requires that the assembly be allowed to use "unsafe" code ( on the plus side, JNI is faster execution than using reflection...)



          public static class ImageReaderEx
          {
          public unsafe static ImageReader NewInstance(int width, int height, Android.Graphics.Format format, int maxImages)
          {
          JniArgumentValue* ptr = stackalloc JniArgumentValue[4];
          *ptr = new JniArgumentValue(width);
          ptr[1] = new JniArgumentValue(height);
          ptr[2] = new JniArgumentValue((int)format);
          ptr[3] = new JniArgumentValue(maxImages);
          JniPeerMembers _members = new XAPeerMembers("android/media/ImageReader", typeof(ImageReader));
          return Java.Lang.Object.GetObject<ImageReader>(_members.StaticMethods.InvokeObjectMethod("newInstance.(IIII)Landroid/media/ImageReader;", ptr).Handle, JniHandleOwnership.TransferLocalRef);
          }

          public unsafe static ImageReader NewInstance(int width, int height, int format, int maxImages)
          {
          JniArgumentValue* ptr = stackalloc JniArgumentValue[4];
          *ptr = new JniArgumentValue(width);
          ptr[1] = new JniArgumentValue(height);
          ptr[2] = new JniArgumentValue(format);
          ptr[3] = new JniArgumentValue(maxImages);
          JniPeerMembers _members = new XAPeerMembers("android/media/ImageReader", typeof(ImageReader));
          return Java.Lang.Object.GetObject<ImageReader>(_members.StaticMethods.InvokeObjectMethod("newInstance.(IIII)Landroid/media/ImageReader;", ptr).Handle, JniHandleOwnership.TransferLocalRef);
          }
          }


          Usage:



          var imageReader = ImageReaderEx.NewInstance(1, 1, 3, 1);


          or



          var ImageReader = ImageReaderEx.NewInstance(1, 1, Android.Graphics.Format.Rgb888, 1);






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 at 8:15

























          answered Nov 11 at 22:29









          SushiHangover

          50.3k53886




          50.3k53886












          • which jar file I should use for binding? and where to find them?
            – VINNUSAURUS
            Nov 12 at 5:46










          • No jar file needed.
            – Cheesebaron
            Nov 12 at 6:48










          • @VINNUSAURUS No jar file, just via Java reflection or JNI, if you do not know how, I can help you with code later (not at my PC)
            – SushiHangover
            Nov 12 at 7:35












          • can u show me how, because I cannot understand it, I am new to this, i will wait for the code.
            – VINNUSAURUS
            Nov 12 at 7:39












          • @VINNUSAURUS I added an example
            – SushiHangover
            Nov 12 at 8:19


















          • which jar file I should use for binding? and where to find them?
            – VINNUSAURUS
            Nov 12 at 5:46










          • No jar file needed.
            – Cheesebaron
            Nov 12 at 6:48










          • @VINNUSAURUS No jar file, just via Java reflection or JNI, if you do not know how, I can help you with code later (not at my PC)
            – SushiHangover
            Nov 12 at 7:35












          • can u show me how, because I cannot understand it, I am new to this, i will wait for the code.
            – VINNUSAURUS
            Nov 12 at 7:39












          • @VINNUSAURUS I added an example
            – SushiHangover
            Nov 12 at 8:19
















          which jar file I should use for binding? and where to find them?
          – VINNUSAURUS
          Nov 12 at 5:46




          which jar file I should use for binding? and where to find them?
          – VINNUSAURUS
          Nov 12 at 5:46












          No jar file needed.
          – Cheesebaron
          Nov 12 at 6:48




          No jar file needed.
          – Cheesebaron
          Nov 12 at 6:48












          @VINNUSAURUS No jar file, just via Java reflection or JNI, if you do not know how, I can help you with code later (not at my PC)
          – SushiHangover
          Nov 12 at 7:35






          @VINNUSAURUS No jar file, just via Java reflection or JNI, if you do not know how, I can help you with code later (not at my PC)
          – SushiHangover
          Nov 12 at 7:35














          can u show me how, because I cannot understand it, I am new to this, i will wait for the code.
          – VINNUSAURUS
          Nov 12 at 7:39






          can u show me how, because I cannot understand it, I am new to this, i will wait for the code.
          – VINNUSAURUS
          Nov 12 at 7:39














          @VINNUSAURUS I added an example
          – SushiHangover
          Nov 12 at 8:19




          @VINNUSAURUS I added an example
          – SushiHangover
          Nov 12 at 8:19












          up vote
          0
          down vote













          In Xamarin, its Format.Rgba8888 (lower case). the doc is here






          share|improve this answer





















          • That will not work as ImageReader.NewInstance does not accept a Format enum as a parameter, it is an issue in the auto-generated API bindings...
            – SushiHangover
            Nov 11 at 22:30















          up vote
          0
          down vote













          In Xamarin, its Format.Rgba8888 (lower case). the doc is here






          share|improve this answer





















          • That will not work as ImageReader.NewInstance does not accept a Format enum as a parameter, it is an issue in the auto-generated API bindings...
            – SushiHangover
            Nov 11 at 22:30













          up vote
          0
          down vote










          up vote
          0
          down vote









          In Xamarin, its Format.Rgba8888 (lower case). the doc is here






          share|improve this answer












          In Xamarin, its Format.Rgba8888 (lower case). the doc is here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 22:21









          navylover

          3,24021118




          3,24021118












          • That will not work as ImageReader.NewInstance does not accept a Format enum as a parameter, it is an issue in the auto-generated API bindings...
            – SushiHangover
            Nov 11 at 22:30


















          • That will not work as ImageReader.NewInstance does not accept a Format enum as a parameter, it is an issue in the auto-generated API bindings...
            – SushiHangover
            Nov 11 at 22:30
















          That will not work as ImageReader.NewInstance does not accept a Format enum as a parameter, it is an issue in the auto-generated API bindings...
          – SushiHangover
          Nov 11 at 22:30




          That will not work as ImageReader.NewInstance does not accept a Format enum as a parameter, it is an issue in the auto-generated API bindings...
          – SushiHangover
          Nov 11 at 22:30


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53253632%2funable-to-find-pixelformat-enum-for-xamarin-android%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Florida Star v. B. J. F.

          Danny Elfman

          Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues