public unsafe void SavePng(string file) { var OutputTexture = new TexHandle(); OutputTexture.Width = (uint)Width; OutputTexture.Height = (uint)Height; OutputTexture.Data = Marshal.AllocHGlobal(Width * Height * 4); uint *data = (uint *)OutputTexture.Data.ToPointer(); for (int i = 0; i < Bitmaps.Count; ++i) { var bitmap = Bitmaps[i]; uint *src = (uint *)bitmap.Data; if (Points[i].dupID < 0) { if (Points[i].rot) { int r = bitmap.Height - 1; for (int y = 0; y < bitmap.Width; ++y) { for (int x = 0; x < bitmap.Height; ++x) { data[(Points[i].y + y) * Width + (Points[i].x + x)] = src[((r - x) * bitmap.Width) + y]; } } } else { for (int y = 0; y < bitmap.Height; ++y) { for (int x = 0; x < bitmap.Width; ++x) { data[(Points[i].y + y) * Width + (Points[i].x + x)] = src[(y * bitmap.Width) + x]; } } } } } TextureLoadUtil.OutTexture(file, ref OutputTexture); }