Axiom.Platform.Android.AndroidImageCodec.Decode C# (CSharp) Method

Decode() public method

public Decode ( System input, System output ) : object
input System
output System
return object
		public override object Decode( System.IO.Stream input, System.IO.Stream output, params object[] args )
		{
			ImageData data = new ImageData();

			Bitmap bitmap = null;

			try
			{
				bitmap = BitmapFactory.DecodeStream( input );

				Bitmap.Config config = bitmap.GetConfig();
				int[] pixels;

				data.height = bitmap.Height;
				data.width = bitmap.Width;
				data.depth = 1;
				data.numMipMaps = 0;

				if ( config != null )
				{
					data.format = Convert( config );

					pixels = new int[ bitmap.Width * bitmap.Height ];
				}
				else
				{
					data.format = Media.PixelFormat.A8R8G8B8;

					pixels = new int[ bitmap.Width * bitmap.Height ];

					for( int x = 0; x < bitmap.Width; x++)
						for ( int y = 0; y < bitmap.Height; y++ )
						{
							int color = x % 2 * y % 2;
							pixels[ x * y + x ] = color * Int32.MaxValue;
						}
				}
				// Start writing from bottom row, to effectively flip it in Y-axis
				bitmap.GetPixels( pixels, pixels.Length - bitmap.Width, -bitmap.Width, 0, 0, bitmap.Width, bitmap.Height );

				IntPtr sourcePtr = Memory.PinObject( pixels );
				byte[] outputBytes = new byte[ bitmap.Width * bitmap.Height * Marshal.SizeOf( typeof( int ) ) ];

				IntPtr destPtr = Memory.PinObject( outputBytes );

				Memory.Copy( sourcePtr, destPtr, outputBytes.Length );


				output.Write( outputBytes, 0, outputBytes.Length );

				return data;
			}
			finally
			{
				if ( bitmap != null )
				{
					bitmap.Recycle();
				}
			}
		}