public static TexBitmap SoftImageFetch(Stream stream, AbstractTextureRef texRef) { Image <Rgba32> result = null; try { result = Image.Load(stream); } catch (Exception) { return(new TexBitmap() { Data = new byte[0] }); } stream.Close(); if (result == null) { return(null); } return(new TexBitmap { Data = result.SavePixelData(), Width = result.Width, Height = result.Height, PixelSize = 4 }); }
public static TexBitmap SoftImageFetch(Stream stream, AbstractTextureRef texRef) { Image result = null; try { result = Image.FromStream(stream); } catch (Exception) { return(new TexBitmap() { Data = new byte[0] }); } stream.Close(); if (result == null) { return(null); } var image = new Bitmap(result); var data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, image.PixelFormat); var pixelSize = image.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb ? 4 : 3; var padding = data.Stride - (data.Width * pixelSize); var bytes = new byte[data.Height * data.Stride]; Marshal.Copy(data.Scan0, bytes, 0, bytes.Length); return(new TexBitmap { Data = bytes, Width = image.Width, Height = image.Height, PixelSize = pixelSize }); }
public static TexBitmap SoftImageFetch(Stream stream, AbstractTextureRef texRef) { Image <Rgba32> result = null; try { result = Image.Load(stream); } catch (Exception) { return(new TexBitmap() { Data = new byte[0] }); } stream.Close(); if (result == null) { return(null); } var data = result.SavePixelData(); for (int i = 0; i < data.Length; i += 4) { var temp = data[i]; data[i] = data[i + 2]; data[i + 2] = temp; } return(new TexBitmap { Data = data, Width = result.Width, Height = result.Height, PixelSize = 4 }); }