Beispiel #1
0
        public void SaveAsJpeg(Stream stream, int width, int height)
        {
            int    len  = Width * Height * GetFormatSize(Format);
            IntPtr data = Marshal.AllocHGlobal(len);

            FNA3D.FNA3D_GetTextureData2D(
                GraphicsDevice.GLDevice,
                texture,
                0,
                0,
                Width,
                height,
                0,
                data,
                len
                );

            FNA3D.WriteJPGStream(
                stream,
                Width,
                Height,
                width,
                height,
                data,
                100                 // FIXME: What does XNA pick for quality? -flibit
                );

            Marshal.FreeHGlobal(data);
        }
Beispiel #2
0
        public void SaveAsPng(Stream stream, int width, int height)
        {
            int    len  = Width * Height * GetFormatSize(Format);
            IntPtr data = Marshal.AllocHGlobal(len);

            FNA3D.FNA3D_GetTextureData2D(
                GraphicsDevice.GLDevice,
                texture,
                0,
                0,
                Width,
                height,
                0,
                data,
                len
                );


            FNA3D.WritePNGStream(
                stream,
                Width,
                Height,
                width,
                height,
                data
                );

            Marshal.FreeHGlobal(data);
        }
Beispiel #3
0
        public void GetData <T>(
            int level,
            Rectangle?rect,
            T[] data,
            int startIndex,
            int elementCount
            ) where T : struct
        {
            if (data == null || data.Length == 0)
            {
                throw new ArgumentException("data cannot be null");
            }
            if (data.Length < startIndex + elementCount)
            {
                throw new ArgumentException(
                          "The data passed has a length of " + data.Length.ToString() +
                          " but " + elementCount.ToString() + " pixels have been requested."
                          );
            }

            int subX, subY, subW, subH;

            if (rect == null)
            {
                subX = 0;
                subY = 0;
                subW = Width >> level;
                subH = Height >> level;
            }
            else
            {
                subX = rect.Value.X;
                subY = rect.Value.Y;
                subW = rect.Value.Width;
                subH = rect.Value.Height;
            }

            int elementSizeInBytes = Marshal.SizeOf(typeof(T));

            ValidateGetDataFormat(Format, elementSizeInBytes);

            GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            FNA3D.FNA3D_GetTextureData2D(
                GraphicsDevice.GLDevice,
                texture,
                subX,
                subY,
                subW,
                subH,
                level,
                handle.AddrOfPinnedObject() + (startIndex * elementSizeInBytes),
                elementCount * elementSizeInBytes
                );
            handle.Free();
        }