public async Task <byte[]> RotateImageAsync(byte[] originalImage, SideOrientation orientation, ImageFormat imageFormat) { byte[] resultImage = null; WriteableBitmap bitmapImage = await originalImage.ToBitmapImageAsync(); MemoryStream memoryStream = new MemoryStream(originalImage); using (IRandomAccessStream randomAccessStream = memoryStream.AsRandomAccessStream()) { BitmapDecoder decoder = await BitmapDecoder.CreateAsync(randomAccessStream); var resizedStream = new InMemoryRandomAccessStream(); BitmapEncoder encoder = await BitmapEncoder.CreateForTranscodingAsync(resizedStream, decoder); encoder.BitmapTransform.InterpolationMode = BitmapInterpolationMode.Linear; encoder.BitmapTransform.Rotation = orientation == SideOrientation.RotateToRigth ? BitmapRotation.Clockwise90Degrees : BitmapRotation.Clockwise270Degrees; await encoder.FlushAsync(); resizedStream.Seek(0); resultImage = new byte[resizedStream.Size]; await resizedStream.ReadAsync(resultImage.AsBuffer(), (uint)resizedStream.Size, InputStreamOptions.None); } return(resultImage); }
public async Task <byte[]> RotateImageAsync(byte[] originalImage , SideOrientation orientation, ImageFormat imageFormat) { byte[] resulImage = null; UIKit.UIImage uiImage = await originalImage.ToImageAsync(); CGBitmapContext bitmapContext = new CGBitmapContext(IntPtr.Zero, (int)uiImage.Size.Height, (int)uiImage.Size.Width, uiImage.CGImage.BitsPerComponent, uiImage.CGImage.BytesPerRow, uiImage.CGImage.ColorSpace, uiImage.CGImage.AlphaInfo); bitmapContext.RotateCTM(orientation == SideOrientation.RotateToRigth ? (-(float)Math.PI / 2) : (float)Math.PI / 2); bitmapContext.TranslateCTM(orientation == SideOrientation.RotateToRigth ? -(int)uiImage.Size.Width : 0, orientation == SideOrientation.RotateToRigth ? 0 : -(int)uiImage.Size.Height); bitmapContext.DrawImage(new CoreGraphics.CGRect(0, 0, (int)uiImage.Size.Width, (int)uiImage.Size.Height), uiImage.CGImage); UIImage resultUIImage = UIImage.FromImage(bitmapContext.ToImage()); if (imageFormat == ImageFormat.JPG) { resulImage = resultUIImage.AsJPEG().ToArray(); } else { resulImage = resultUIImage.AsPNG().ToArray(); } return(resulImage); }
bool IsSky(Linedef line, bool front, SideOrientation orientation) { if (orientation == SideOrientation.Middle) { return(false); } Sector backSector = map.sectors[map.sidedefs[front?line.back:line.front].sector]; switch (orientation) { case SideOrientation.Upper: if (backSector.ceilingTexture == "F_SKY1") { return(true); } break; case SideOrientation.Lower: if (backSector.floorTexture == "F_SKY1") { return(true); } break; } return(false); }
public async Task <byte[]> RotateImageAsync(byte[] originalImage, SideOrientation orientation, Abstractions.ImageFormat imageFormat) { byte[] resultRotatedImage = null; Bitmap bitmap = await originalImage.ToBitmapAsync(); Matrix matrix = new Matrix(); matrix.PostRotate(orientation == SideOrientation.RotateToRigth ? 90 : -90); Bitmap rotatedBitmap = Bitmap.CreateBitmap(bitmap, 0, 0, bitmap.Width, bitmap.Height, matrix, true); resultRotatedImage = await rotatedBitmap.ToByteArrayAsync(imageFormat); return(resultRotatedImage); }
Vector2[] CalculateUVs(float length, Vector2 bottomHeight, Vector2 topHeight, Linedef line, bool front, SideOrientation orientation) { Sidedef side = null; side = map.sidedefs[front?line.front:line.back]; float height; string texture; switch (orientation) { case SideOrientation.Upper: texture = side.upper; height = topHeight.y - topHeight.x; break; case SideOrientation.Middle: texture = side.mid; height = topHeight.x - bottomHeight.y; break; case SideOrientation.Lower: texture = side.lower; height = bottomHeight.y - bottomHeight.x; break; default: texture = "-"; height = 1f; break; } Vector2 size = Vector2.one; Vector2 offset = Vector2.zero; if (wad.textureTable.Contains(texture.ToUpper())) { var textureInfo = wad.textureTable.Get(texture.ToUpper()); Vector2 textureSize = new Vector2(textureInfo.width, textureInfo.height); size.x = length / textureSize.x; size.y = height / textureSize.y; offset.x = (float)side.xOffset / textureSize.x; offset.y = (float)side.yOffset / textureSize.y; if (orientation == SideOrientation.Middle) { if (line.lowerUnpegged && !line.upperUnpegged) { // Draw from bottom offset.y -= size.y; } else { } } if (orientation == SideOrientation.Upper) { if (!line.upperUnpegged) { // draw from height ceiling offset.y -= size.y; } } if (orientation == SideOrientation.Lower) { if (!line.lowerUnpegged) { // draw from higher ceiling offset.y += topHeight.y - bottomHeight.y; } else { // offset.y -= size.y; } } } size += offset; return(new Vector2[] { new Vector2(offset.x, size.y), new Vector2(offset.x, offset.y), new Vector2(size.x, offset.y), new Vector2(size.x, size.y) }); }