public void AnalyseLayout_RotatedImage(RotateFlipType? rotation) { using (var img = new Bitmap(@".\phototest.tif")) { if (rotation.HasValue) img.RotateFlip(rotation.Value); engine.DefaultPageSegMode = PageSegMode.AutoOsd; using (var page = engine.Process(img)) { using (var pageLayout = page.GetIterator()) { pageLayout.Begin(); do { var result = pageLayout.GetProperties(); // Note: The orientation always seem to be 'PageUp' in Tesseract 3.02 according to this test. Assert.That(result.Orientation, Is.EqualTo(Orientation.PageUp)); if (rotation == RotateFlipType.Rotate180FlipNone) { // This isn't correct... Assert.That(result.WritingDirection, Is.EqualTo(WritingDirection.LeftToRight)); Assert.That(result.TextLineOrder, Is.EqualTo(TextLineOrder.TopToBottom)); } else if (rotation == RotateFlipType.Rotate90FlipNone) { Assert.That(result.WritingDirection, Is.EqualTo(WritingDirection.TopToBottom)); Assert.That(result.TextLineOrder, Is.EqualTo(TextLineOrder.RightToLeft)); } else if (rotation == null) { Assert.That(result.WritingDirection, Is.EqualTo(WritingDirection.LeftToRight)); Assert.That(result.TextLineOrder, Is.EqualTo(TextLineOrder.TopToBottom)); } // Not sure... } while (pageLayout.Next(PageIteratorLevel.Block)); } } } }
public void RotateFlip(RotateFlipType rotateFlipType) { Bitmap temp = (Bitmap)m_CurrentImage; Bitmap bmap = (Bitmap)temp.Clone(); bmap.RotateFlip(rotateFlipType); m_CurrentImage = (Bitmap)bmap.Clone(); }
/// <summary> /// Resizes and rotates an image, keeping the original aspect ratio. Does not dispose the original /// Image instance. /// </summary> /// <param name="image">Image instance</param> /// <param name="width">desired width</param> /// <param name="height">desired height</param> /// <param name="rotateFlipType">desired RotateFlipType</param> /// <returns>new resized/rotated Image instance</returns> public static System.Drawing.Image Resize(System.Drawing.Image image, int width, int height, RotateFlipType rotateFlipType) { // clone the Image instance, since we don't want to resize the original Image instance var rotatedImage = image.Clone() as System.Drawing.Image; //rotatedImage.RotateFlip(rotateFlipType); var newSize = CalculateResizedDimensions(rotatedImage, width, height); var resizedImage = new Bitmap(newSize.Width, newSize.Height, PixelFormat.Format32bppArgb); resizedImage.SetResolution(72, 72); using (var graphics = Graphics.FromImage(resizedImage)) { // set parameters to create a high-quality thumbnail graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; // use an image attribute in order to remove the black/gray border around image after resize // (most obvious on white images), see this post for more information: // http://www.codeproject.com/KB/GDI-plus/imgresizoutperfgdiplus.aspx using (var attribute = new ImageAttributes()) { attribute.SetWrapMode(WrapMode.TileFlipXY); // draws the resized image to the bitmap graphics.DrawImage(rotatedImage, new Rectangle(new Point(0, 0), newSize), 0, 0, rotatedImage.Width, rotatedImage.Height, GraphicsUnit.Pixel, attribute); } } return resizedImage; }
protected override void addimage(location state, Brand brand, RotateFlipType rotate) { Bitmap bitmap; // �p�G�O�i�����P�N�]�w��ܵP���ϫ��A�_�h�N��ܪ��ߪ��P Resources.upbarnd if (brand.IsCanSee || state == location.South || ShowAll) bitmap = new Bitmap(brand.image); else bitmap = new Bitmap(Resources.upbarnd); // �]�w�P BrandBox tempBrandbox = new BrandBox(brand); // �]�w�۰��Y�� tempBrandbox.SizeMode = PictureBoxSizeMode.AutoSize; // �]�w��Z tempBrandbox.Margin = new Padding(0); tempBrandbox.Padding = new Padding(padding); // �n����� bitmap.RotateFlip(rotate); // ���� if (ShowAll && ShowBrandInfo) tempBrandbox.Click += new EventHandler(debug_Click); // �ƹ��ƥ� if ( state == location.South && brand.getClass() != Settings.Default.Flower && brand.Team < 1 ) { tempBrandbox.MouseMove += new MouseEventHandler(tempBrandbox_MouseMove); tempBrandbox.MouseLeave += new EventHandler(brandBox_MouseLeave); tempBrandbox.Click += new EventHandler(brandBox_MouseClick); // �@���ƥ� //if (ShowAll && ShowBrandInfo) // tempBrandbox.MouseHover += new EventHandler(debug_Click); //else // tempBrandbox.MouseHover -= new EventHandler(debug_Click); } else if (cheat && state != location.South) { tempBrandbox.MouseClick += new MouseEventHandler(cheat_MouseClick); } else { tempBrandbox.Click -= new EventHandler(brandBox_MouseClick); tempBrandbox.MouseClick -= new MouseEventHandler(cheat_MouseClick); } bitmap = ResizeBitmap(bitmap, Settings.Default.ResizePercentage); // �]�w�Ϥ� tempBrandbox.Image = bitmap; // �s�W�ܱ�� add_flowLayoutBrands(state, tempBrandbox); }
public static Bitmap RotateFlip(RotateFlipType rotateFlipType, Bitmap input) { Bitmap temp = input; Bitmap bmap = (Bitmap)temp.Clone(); bmap.RotateFlip(rotateFlipType); return (Bitmap)bmap.Clone(); }
public static RotateFlipType GetFlipTypeRotatedCW(RotateFlipType currentRotation) { RotateFlipType newRotation; switch (currentRotation) { case RotateFlipType.RotateNoneFlipNone: newRotation = RotateFlipType.Rotate90FlipNone; break; case RotateFlipType.Rotate90FlipNone: newRotation = RotateFlipType.Rotate180FlipNone; break; case RotateFlipType.Rotate180FlipNone: case RotateFlipType.RotateNoneFlipY: // legacy images newRotation = RotateFlipType.Rotate270FlipNone; break; case RotateFlipType.Rotate270FlipNone: newRotation = RotateFlipType.RotateNoneFlipNone; break; default: Debug.Fail("Unknown RotateFlipType encountered: " + currentRotation.ToString()); newRotation = RotateFlipType.RotateNoneFlipNone; break; } return newRotation; }
public RotateTool(IDrawingFeatures drawingFeatures, RotateFlipType rotateType) { _drawingFeatures = drawingFeatures; _rotateType = rotateType; _drawingFeatures.DrawingHistory.CanceledShares = new Stack<AUndoable>(); _previousImage = (Bitmap)_drawingFeatures.PaintingArea.Image.Clone(); }
// Modified behavior public void Rotate(RotateFlipType rotation, IEnumerable<Bitmap> images) { if (decorated == null) return; Parallel.ForEach(images, b => { b.RotateFlip(rotation); }); }
public void TOS_FromBitmapTest_05() { string testObject = "TOS_FromBitmapTest_05"; Bitmap bitmap = SWA_Ariadne_Outlines_Resources_TilesAccessor.Tile01_8x8; RotateFlipType rft = RotateFlipType.RotateNoneFlipX; int scale = 1; TestHalfArea(testObject, bitmap, rft, scale); }
private void RotateImage(RotateFlipType rotation) { Image Image = pictureBoxCustom1.Image; if (Image != null) { Image.RotateFlip(rotation); UpdateEditCached(Image); } }
/// <summary> /// Returns a new Image that is equivalent to the specified image, at the specified /// orientation. (The new image is the input image rotated to match the specified /// orientation.) /// /// Note: The rotated image may not be a lossless version of the specified image. /// (I haven't tested to be sure, and the documentation for the Image.RotateFlip /// method used to perform the rotation doesn't address the issue.) This method may /// not be suitable for creating files to be saved out to disk, but it does work /// plenty well enough for in-memory manipulation of thumbnail images. /// </summary> /// <param name="image">The image to be rotated. </param> /// <param name="orientation">The desired orientation of the rotated image. </param> /// <returns>A new image that is equivalent to the input image with the specified /// rotation applied. </returns> public static Image RotateImage(Image image, Orientation orientation) { //Get the RotateFlipType that corresponds to the new orientation. RotateFlipType rotateFlipType = RotateFlipTypeFromOrientation(orientation); Image rotatedImage = (Image)image.Clone(); rotatedImage.RotateFlip(rotateFlipType); return(rotatedImage); }
/// <summary> /// Builds a pattern from a bitmap resource. /// </summary> /// <param name="r"></param> /// <param name="xSize"></param> /// <param name="ySize"></param> /// <returns></returns> public static OutlineShape FromSmallBitmap(Random r) { // Load a random bitmap image. Bitmap bitmap = SWA.Utilities.Resources.CreateBitmap(SmallBitmapProperties, r); RotateFlipType rft = (RotateFlipType)r.Next(8); int scale = 1; return(FromBitmap(bitmap.Width, bitmap.Height, bitmap, rft, scale)); }
public void RotateImage(RotateFlipType flip_type) { Image image = this.pictureBox1.Image; image.RotateFlip(flip_type); pictureBox1.Width = image.Width; pictureBox1.Height = image.Height; ImageUtil.SetImage(pictureBox1, image); // 2016/12/28 }
internal static RotateFlipType GetOrientationTransform(MetadataEntry entry) { RotateFlipType transform = RotateFlipType.RotateNoneFlipNone; if (TryDecodeShort(entry, out ushort exifValue)) { if (exifValue >= 1 && exifValue <= 8) { switch (exifValue) { case 1: // Do nothing transform = RotateFlipType.RotateNoneFlipNone; break; case 2: // Flip horizontally. transform = RotateFlipType.RotateNoneFlipX; break; case 3: // Rotate 180 degrees. transform = RotateFlipType.Rotate180FlipNone; break; case 4: // Flip vertically. transform = RotateFlipType.RotateNoneFlipY; break; case 5: // Rotate 90 degrees clockwise and flip horizontally. transform = RotateFlipType.Rotate90FlipX; break; case 6: // Rotate 90 degrees clockwise. transform = RotateFlipType.Rotate90FlipNone; break; case 7: // Rotate 270 degrees clockwise and flip horizontally. transform = RotateFlipType.Rotate270FlipX; break; case 8: // Rotate 270 degrees clockwise. transform = RotateFlipType.Rotate270FlipNone; break; } } } return(transform); }
public static ImageFile[] LoadCubeImages(string path, string file, string extensio) { List <ImageFile> files = new List <ImageFile>(); string finalPath = path + file + "/"; for (int i = 0; i < 6; i++) { string finalFileName = file; RotateFlipType rotate = RotateFlipType.RotateNoneFlipNone; if (i == 0) { finalFileName = file + "_rt"; } else if (i == 1) { finalFileName = file + "_dn"; } else if (i == 2) { finalFileName = file + "_bk"; } else if (i == 3) { finalFileName = file + "_lf"; } else if (i == 4) { finalFileName = file + "_up"; rotate = RotateFlipType.Rotate90FlipNone; } else if (i == 5) { finalFileName = file + "_ft"; } if (!File.Exists(string.Concat(finalPath, finalFileName, "." + extensio))) { Debug.LogError("Texture Files Can't be found At: " + string.Concat(finalPath, finalFileName, "." + extensio)); throw new Exception("Texture Files Can't be found At: " + string.Concat(finalPath, finalFileName, "." + extensio)); } using (var image = new Bitmap(string.Concat(finalPath, finalFileName, "." + extensio))) { image.RotateFlip(rotate); //image.MakeTransparent(); var data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); files.Add(new ImageFile(data.Scan0, data.Width, data.Height)); } } return(files.ToArray()); }
internal static RotateFlipType GetOrientationTransform(MetadataEntry entry) { RotateFlipType transform = RotateFlipType.RotateNoneFlipNone; if (TryDecodeShort(entry, out ushort exifValue)) { if (exifValue >= TiffConstants.Orientation.TopLeft && exifValue <= TiffConstants.Orientation.LeftBottom) { switch (exifValue) { case TiffConstants.Orientation.TopLeft: // Do nothing transform = RotateFlipType.RotateNoneFlipNone; break; case TiffConstants.Orientation.TopRight: // Flip horizontally. transform = RotateFlipType.RotateNoneFlipX; break; case TiffConstants.Orientation.BottomRight: // Rotate 180 degrees. transform = RotateFlipType.Rotate180FlipNone; break; case TiffConstants.Orientation.BottomLeft: // Flip vertically. transform = RotateFlipType.RotateNoneFlipY; break; case TiffConstants.Orientation.LeftTop: // Rotate 90 degrees clockwise and flip horizontally. transform = RotateFlipType.Rotate90FlipX; break; case TiffConstants.Orientation.RightTop: // Rotate 90 degrees clockwise. transform = RotateFlipType.Rotate90FlipNone; break; case TiffConstants.Orientation.RightBottom: // Rotate 270 degrees clockwise and flip horizontally. transform = RotateFlipType.Rotate270FlipX; break; case TiffConstants.Orientation.LeftBottom: // Rotate 270 degrees clockwise. transform = RotateFlipType.Rotate270FlipNone; break; } } } return(transform); }
public static string CreateThumbnail(int maxWidth, int maxHeight, string path, string savePath, Image image, string ContentType) { //var image = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(path)); var ratioX = (double)maxWidth / image.Width; var ratioY = (double)maxHeight / image.Height; var ratio = Math.Min(ratioX, ratioY); var newWidth = (int)(image.Width * ratio); var newHeight = (int)(image.Height * ratio); var newImage = new Bitmap(newWidth, newHeight); Graphics thumbGraph = Graphics.FromImage(newImage); thumbGraph.CompositingQuality = CompositingQuality.HighQuality; thumbGraph.SmoothingMode = SmoothingMode.HighQuality; //thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic; //foreach (PropertyItem pi in image.PropertyItems) //{ // if (pi.Id == 0x0112) // { // image.RotateFlip(RotateFlipType.Rotate90FlipNone); // } //} //image.RotateFlip(RotateFlipType.Rotate90FlipNone); //image.RotateFlip(RotateFlipType.Rotate90FlipNone); //image.RotateFlip(RotateFlipType.Rotate90FlipNone); foreach (var prop in image.PropertyItems) { if (prop.Id == 0x0112) //value of EXIF { int orientationValue = image.GetPropertyItem(prop.Id).Value[0]; RotateFlipType rotateFlipType = ImageHelper.GetOrientationToFlipType(orientationValue); image.RotateFlip(rotateFlipType); break; } } thumbGraph.DrawImage(image, 0, 0, newWidth, newHeight); image.Dispose(); string fileRelativePath = "newsizeimages/" + maxWidth + Path.GetFileName(path); //newImage.Save(HttpContext.Current.Server.MapPath(savePath), newImage.RawFormat); //thumbGraph.Dispose(); if (string.IsNullOrWhiteSpace(ContentType) || ContentType.ToLower() != "propertylogo") { AddWaterMarkLogo(newImage, savePath); } else { SaveImage(newImage, savePath); } thumbGraph.Dispose(); newImage.Dispose(); return(savePath); }
/// <summary> /// Creates a new instance of <see cref="RotatedImageProvider"/>. /// </summary> /// <param name="Source">The source <see cref="IImageProvider"/>.</param> /// <param name="RotateFlipType">Rotation and/or Flipping options.</param> /// <exception cref="ArgumentNullException"><paramref name="Source"/> is null.</exception> public RotatedImageProvider(IImageProvider Source, RotateFlipType RotateFlipType) { _sourceImageProvider = Source ?? throw new ArgumentNullException(nameof(Source)); _rotateFlipType = RotateFlipType; var flipDimensions = (int)RotateFlipType % 2 != 0; Width = flipDimensions ? Source.Height : Source.Width; Height = flipDimensions ? Source.Width : Source.Height; }
/// <summary> /// /// </summary> /// <param name="type"></param> public void Flip(RotateFlipType type) { if (type != RotateFlipType.RotateNoneFlipNone) { Bitmap clone = new Bitmap(this.image); ///TODO: The RotateFlip transformation converts bitmaps to memoryBmp? this.image.RotateFlip(type); Convert(this.format); OnChanged(new ImageChangedEventArgs("Flip", clone)); } }
public static RotateFlipType CombineFlipAndRotate(RotateFlipType flip, double angle) { if (flip != (RotateFlipType)FlipMode.None && flip != (RotateFlipType)FlipMode.X && flip != (RotateFlipType)FlipMode.Y && flip != (RotateFlipType)FlipMode.XY) { throw new ArgumentException("Valid flip values are RotateNoneFlipNone, RotateNoneFlipX, RotateNoneFlipY, and RotateNoneFlipXY. Rotation must be specified with Rotate or srcRotate instead. Received: " + flip.ToString()); } return(CombineFlipAndRotate((FlipMode)flip, angle)); }
public RadImageShape() { this.interpolationMode = InterpolationMode.NearestNeighbor; this.paintMode = ImagePaintMode.Stretch; this.rotateFlip = RotateFlipType.RotateNoneFlipNone; this.useSegments = true; this.visibleSegments = ImageSegments.All; this.alpha = 1f; this.imageDirty = true; this.segmentsDirty = true; }
public static Bitmap RotateFlipClone(this Bitmap value, RotateFlipType transform) { if (value == null) { return(null); } value = (Bitmap)value.Clone(); value.RotateFlip(transform); return(value); }
// Modified behavior public void Rotate(RotateFlipType rotation, IEnumerable <Bitmap> images) { if (decorated == null) { return; } Parallel.ForEach(images, b => { b.RotateFlip(rotation); }); }
private Bitmap tryGetFromCache(string path, RotateFlipType rotations) { if (!_imagesByPath.TryGetValue(new Tuple <string, RotateFlipType>(path, rotations), out var cacheEntry)) { return(null); } shiftFromLast(cacheEntry); return(cacheEntry.Image); }
public static Image GetBitmap(byte[] source, RotateFlipType rotate) { using (var strm = new MemoryStream(source, true)) { strm.Write(source, 0, source.Length); Image im = new Bitmap(strm); im.RotateFlip(rotate); strm.Close(); return(im); } }
private static void OnFlipPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { var self = (MainViewModel)sender; RotateFlipType type = self._rotateType; if (self.IsFlipX) { type |= RotateFlipType.RotateNoneFlipX; } self._webcam.RotateFlipType = type; }
public virtual Image GetFramedPhoto(int outputLength, int borderLength, int paddingLength, int dropShadowLength, Color borderColor, Color paddingColor, Color dropshadowColor, Color backgroundColor) { using (FileStream fs = new FileStream(this.fileInfo.FullName, FileMode.Open, FileAccess.Read)) { using (Image image = Image.FromStream(fs, true, false)) { RotateFlipType flip = OrientationToFlipType(this.orientation); return(GetThumbnail(image, flip)); } } }
private void ok_Click(object sender, EventArgs e) { if (activeButton.Name == "Angle") { type = (RotateFlipType)Enum.Parse(typeof(RotateFlipType), activeAngle.Name); } else { type = (RotateFlipType)Enum.Parse(typeof(RotateFlipType), activeButton.Name); } }
private void UpdateMfdManagerScreenBounds(RotateFlipType rotation) { if (rotation == RotateFlipType.Rotate180FlipNone || rotation == RotateFlipType.RotateNoneFlipNone) { _manager.ScreenBoundsPixels = new Size(DesktopBounds.Width, DesktopBounds.Height); } else { _manager.ScreenBoundsPixels = new Size(DesktopBounds.Height, DesktopBounds.Width); } }
public override void Rotate(RotateFlipType rotateFlipType) { Bitmap newBitmap = ImageHelper.RotateFlip((Bitmap)bitmap, rotateFlipType); if (bitmap != null) { bitmap.Dispose(); } bitmap = newBitmap; base.Rotate(rotateFlipType); }
public void AppendTexture(object img, Rectangle rect, byte layer = 0, RotateFlipType flipMode = RotateFlipType.RotateNoneFlipNone) { CompositData composit = new CompositData(DrawMode.Rect, DrawType.Texture); composit.Texture = img; composit.Layer = layer; composit.Rect = rect; composit.FlipMode = flipMode; layers.Add(composit); }
/// <summary> /// Partially implementing Image.RotateFlip (RotateFlipType) from System.Drawing for Rectangle. /// Incorrect for default usage, only Kontur.ImageTransformer /// </summary> /// <param name="rect">Rectangle for transformation</param> /// <param name="rotateFlipType">Combination of rotate and flip</param> /// <param name="srcW">Width of original image</param> /// <param name="srcH">Height of original image</param> /// <exception cref="NotImplementedException">Implemented only needed consts</exception> public static Rectangle RotateFlip(this Rectangle rect, RotateFlipType rotateFlipType, int srcW, int srcH) { int t; if (rect.Width < 0 || rect.Width < 0) { rect = rect.Normalise(); } switch (rotateFlipType) { case RotateFlipType.RotateNoneFlipNone: // == Rotate180FlipXY break; case RotateFlipType.Rotate90FlipNone: // == Rotate270FlipXY cw t = rect.Y; rect.Y = srcH - rect.Right; rect.X = t; t = rect.Width; rect.Width = rect.Height; rect.Height = t; break; case RotateFlipType.Rotate270FlipNone: // == Rotate90FlipXY ccw t = rect.X; rect.X = srcW - rect.Bottom; rect.Y = t; t = rect.Width; rect.Width = rect.Height; rect.Height = t; break; case RotateFlipType.RotateNoneFlipX: // == Rotate180FlipY h rect.X = srcW - rect.Right; rect.Y = rect.Y; rect.Width = rect.Width; rect.Height = rect.Height; break; case RotateFlipType.RotateNoneFlipY: // == Rotate180FlipX v rect.X = rect.X; rect.Y = srcH - rect.Bottom; rect.Width = rect.Width; rect.Height = rect.Height; break; default: throw new NotImplementedException(); } return(rect); }
public static bool RotationatePathIfNeeded(string path, RotateFlipType type) { if (type == RotateFlipType.RotateNoneFlipNone) return false; var bmp = Bitmap.FromFile (path); bmp.RotateFlip (type); bmp.Save (path); return true; }
public static void RotateImageFile( string filePath, RotateFlipType rotateFlipType) { FileSystemHelper.ValidateFileExists(filePath); using (Image image = Image.FromFile(filePath)) { image.RotateFlip(rotateFlipType); image.Save(filePath, ImageFormat.Png); } }
private void buttonClockwise_Click(object sender, EventArgs e) { RotateFlipType newRotation = ImageDecoratorUtils.GetFlipTypeRotatedCW(EditorContext.ImageRotation); EditorContext.ImageRotation = newRotation; using (new WaitCursor()) { EditorContext.ApplyDecorator(); } }
public static unsafe void RotateFlip(ref ImageAttributes source, RotateFlipType rft) { Bitmap bitmap = OtherImageFormats.GetBitmap(source, null, null, false); bitmap.RotateFlip(rft); DataSet dicom = OtherImageFormats.GetImage(bitmap); source.height = bitmap.Height; source.width = source.stride = bitmap.Width; Array.Copy((Array)dicom[t.PixelData].Value, source.buffer, source.buffer.Length); }
private Image RotateImageStream(ImageOrientation orientation, byte imageFormat) { RotateFlipType flipType = RotateFlipType.RotateNoneFlipNone; if (_ImageOrientation != orientation) { flipType = RotateFlipType.Rotate90FlipNone; } return(RotateImageStream(flipType, imageFormat)); }
public ImageOrientation(int orientation) { if (0 <= orientation && orientation < rf_table.Length) { rf = rf_table[orientation]; } else { throw new Exception(); } }
/// <summary> /// Rotates and or flips the image base on the RotateFlipTyp value passed. /// </summary> /// <param name="rotateFlipType">Rotate flip type.</param> public void RotateFlip(RotateFlipType rotateFlipType) { var b = this as Bitmap; if (b == null) { return; } b.RotateFlip(rotateFlipType); }
public static Image RotateImage(Image img, RotateFlipType type) { var bmp = new Bitmap(img); using (Graphics gfx = Graphics.FromImage(bmp)) { gfx.Clear(Color.White); gfx.DrawImage(img, 0, 0, img.Width, img.Height); } bmp.RotateFlip(type); return bmp; }
public static bool IsRotated90(RotateFlipType rotation) { switch (rotation) { case RotateFlipType.Rotate90FlipNone: case RotateFlipType.Rotate90FlipX: case RotateFlipType.Rotate90FlipXY: case RotateFlipType.Rotate90FlipY: return true; default: return false; } }
private int DrawTile(int Tile, int X, int Y, RotateFlipType Rotate) { Paifu.PaifuTileImage TileImage = new Paifu.PaifuTileImage(Tile, Scale, Red); Bitmap TileBitmap = TileImage.Bmp; switch (Rotate) { case RotateFlipType.Rotate90FlipNone: TileBitmap.RotateFlip(Rotate); Y += (TileHeight - TileWidth); break; case RotateFlipType.Rotate270FlipNone: TileBitmap.RotateFlip(Rotate); Y += (TileHeight - TileWidth); break; } G.DrawImage(TileBitmap, new Point(X, Y)); return TileBitmap.Width; }
public CScanViewer() { InitializeComponent(); this.Location = new Point(10, 10); this.Size = new Size(10, 10); this.Visible = true; rotate = RotateFlipType.Rotate90FlipNone; // RotateFlipType.Rotate90FlipXY frameSize = new Size(0, 0); this.NewFrame += new AForge.Controls.VideoSourcePlayer.NewFrameHandler(frameHandler); this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mouseDownHandler); this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.mouseUpHandler); this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.mouseMoveHandler); }
public void ImageRecognized(long metric, RotateFlipType rotate, List<RecognizedWord> words) { lock (metrics) { metrics[rotate] = metric; } lock (imagesWords) { imagesWords[rotate] = words; } if (Interlocked.Decrement(ref OperationsRemain) == 0) { isImagesParsingDone.Set(); } }
void okButton_Click(object sender, RoutedEventArgs e) { this.DialogResult = true; try { if (RB90.IsChecked.HasValue && RB90.IsChecked.Value) angle = RotateFlipType.Rotate90FlipNone; else if (RB180.IsChecked.HasValue && RB180.IsChecked.Value) angle = RotateFlipType.Rotate180FlipNone; else if (RB270.IsChecked.HasValue && RB270.IsChecked.Value) angle = RotateFlipType.Rotate270FlipNone; } catch (Exception ex) { Console.Error.WriteLine(ex.Data); } }
void okButton_Click(object sender, RoutedEventArgs e) { this.DialogResult = true; try { if (CBHoriz.IsChecked.HasValue && CBHoriz.IsChecked.Value && CBVert.IsChecked.HasValue && CBVert.IsChecked.Value) mirror = RotateFlipType.RotateNoneFlipXY; else if (CBHoriz.IsChecked.HasValue && CBHoriz.IsChecked.Value) mirror = RotateFlipType.RotateNoneFlipX; else if (CBVert.IsChecked.HasValue && CBVert.IsChecked.Value) mirror = RotateFlipType.RotateNoneFlipY; } catch (Exception ex) { Console.Error.WriteLine(ex.Data); } }
/// <summary> /// Rotates a given animation /// </summary> /// <param name="image">Target image</param> /// <param name="rotation">Desired rotation</param> /// <param name="counterRotation">The complement of the desired rotation</param> /// <returns>Transformed image</returns> public virtual Bitmap RotateAnimation(Bitmap image, RotateFlipType rotation, RotateFlipType counterRotation) { // The idea lies in rotating the returnBitmap and "drawing" the "image" on the rotated // returnBitmap Then returnBitmap is rotated to the complementing ( 360 - rotation ) // direction so the image seems normal Bitmap returnBitmap = new Bitmap(animationWidth, animationHeight); //make a graphics object from the empty bitmap using (Graphics gx = Graphics.FromImage(returnBitmap)) { returnBitmap.RotateFlip(rotation); // ex:Rotate 90 //draw passed in image onto graphics object gx.InterpolationMode = InterpolationMode.HighQualityBicubic; gx.DrawImage(image, 0, 0, animationWidth, animationHeight); returnBitmap.RotateFlip(counterRotation); // ex:Rotate 270 back } return returnBitmap; }
public RotationTransform(RotateFlipType rotateFlipType) { switch (rotateFlipType) { case RotateFlipType.Rotate90FlipNone: Angle = 90.0; break; case RotateFlipType.Rotate180FlipNone: Angle = 180.0; break; case RotateFlipType.Rotate270FlipNone: Angle = 270.0; break; case RotateFlipType.RotateNoneFlipNone: Angle = 0.0; break; default: throw new ArgumentException(); } }
public static void CreateImage (RotateFlipType rotate, int movex, int movey, string text, Bitmap dest, Graphics grdest) { Color clr; Bitmap bmp = new Bitmap (80, 80, PixelFormat.Format32bppArgb); Graphics gr = Graphics.FromImage (bmp); gr.Clear (Color.White); gr.DrawLine (p, 10.0F, 10.0F, 70.0F, 70.0F); gr.DrawLine (p, 10.0F, 15.0F, 70.0F, 15.0F); gr.DrawRectangle (p, 10.0F, 10.0F, 60.0F, 60.0F); bmp.RotateFlip (rotate); for (int y = 0; y < 80; y++) { for (int x = 0; x < 80; x++) { clr = bmp.GetPixel (x,y); dest.SetPixel (x+movex, y+movey, clr); } } grdest.DrawString (text, new Font ("Arial", 8), br, movex+5, movey+85); }
/// <summary>图像旋转 /// </summary> /// <param name="source">原始图像</param> /// <param name="rotateFlipType">旋转类型</param> public static Bitmap Rotate(Bitmap source, RotateFlipType rotateFlipType) { if (source == null) throw new ArgumentNullException("source"); Rectangle rect = new Rectangle(0, 0, source.Width, source.Height); Bitmap target = source.Clone(rect, PixelFormat.Format24bppRgb); target.RotateFlip(rotateFlipType); return target; }
private void RotateAndSaveImage(String input, String output, ImageFormat format, RotateFlipType type) { //create an object that we can use to examine an image file System.Drawing.Image img = System.Drawing.Image.FromFile(input); //rotate the picture by 90 degrees img.RotateFlip(type); //re-save the picture img.Save(output, format); //tidy up after we've finished img.Dispose(); }
private void SaveRotateFlip(RotateFlipType rotateFlipType) { this.Image.RotateFlip(rotateFlipType); this.Image.Save(this.FileName); }
public bool DetectQRCode() { var qrReader = new QRCodeMultiReader(); var qrReaderHints = new Dictionary<DecodeHintType, object>() { { DecodeHintType.TRY_HARDER, true } }; var qrImageSource = new BitmapLuminanceSource((Bitmap)Image); var qrBinarizer = new HybridBinarizer(qrImageSource); var qrBinaryBitmap = new BinaryBitmap(qrBinarizer); try { qrCodeResult = qrReader.decodeMultiple(qrBinaryBitmap, qrReaderHints)?.FirstOrDefault(); qrCodeResultScale = 1F; } catch (ReaderException) { // QR Detection Failed qrCodeResult = null; } if (qrCodeResult == null) { var sizePoints = PdfiumDocument.PageSizes[PageIndex]; // Try at 175% using (var image = PdfiumDocument.Render(PageIndex, (int)(sizePoints.Width * 1.75), (int)(sizePoints.Height * 1.75), 72F, 72F, false)) { qrImageSource = new BitmapLuminanceSource((Bitmap)image); // Try Entire Image qrBinarizer = new HybridBinarizer(qrImageSource); qrBinaryBitmap = new BinaryBitmap(qrBinarizer); try { qrCodeResult = qrReader.decodeMultiple(qrBinaryBitmap, qrReaderHints)?.FirstOrDefault(); qrCodeResultScale = 1.75F; } catch (ReaderException) { // QR Detection Failed qrCodeResult = null; } } if (qrCodeResult == null) { // Try at 200% using (var image = PdfiumDocument.Render(PageIndex, (int)(sizePoints.Width * 2), (int)(sizePoints.Height * 2), 72F, 72F, false)) { qrImageSource = new BitmapLuminanceSource((Bitmap)image); // Try Entire Image qrBinarizer = new HybridBinarizer(qrImageSource); qrBinaryBitmap = new BinaryBitmap(qrBinarizer); try { qrCodeResult = qrReader.decodeMultiple(qrBinaryBitmap, qrReaderHints)?.FirstOrDefault(); qrCodeResultScale = 2F; } catch (ReaderException) { // QR Detection Failed qrCodeResult = null; } } } } if (qrCodeResult != null) { // Detect Rotation var rotationAngle = Math.Atan2( qrCodeResult.ResultPoints[2].Y - qrCodeResult.ResultPoints[1].Y, qrCodeResult.ResultPoints[2].X - qrCodeResult.ResultPoints[1].X) * 180 / Math.PI; if (rotationAngle <= 45 || rotationAngle > 315) { detectedRotation = RotateFlipType.RotateNoneFlipNone; } else if (rotationAngle <= 135) { detectedRotation = RotateFlipType.Rotate270FlipNone; } else if (rotationAngle <= 225) { detectedRotation = RotateFlipType.Rotate180FlipNone; } else { detectedRotation = RotateFlipType.Rotate90FlipNone; } // Reset Thumbnail if (renderedThumbnail != null) { renderedThumbnail.Dispose(); renderedThumbnail = null; } // Try binary encoding (from v2) if (qrCodeResult.ResultMetadata.ContainsKey(ResultMetadataType.BYTE_SEGMENTS)) { var byteSegments = (List<byte[]>)qrCodeResult.ResultMetadata[ResultMetadataType.BYTE_SEGMENTS]; var qrBytes = byteSegments[0]; if (DocumentUniqueIdentifier.IsDocumentUniqueIdentifier(qrBytes)) { Identifier = DocumentUniqueIdentifier.Parse(Database, qrBytes); } } // Fall back to v1 if (Identifier == null) { Identifier = DocumentUniqueIdentifier.Parse(Database, qrCodeResult.Text); } return true; } return false; }
internal static Bitmap ResizeImage(Bitmap image, Size newSize, RotateFlipType rotation) { if (rotation != RotateFlipType.RotateNoneFlipNone) { image.RotateFlip(rotation); image = new Bitmap(image); } int newWidth = Math.Max(newSize.Width, 2); int newHeight = Math.Max(newSize.Height, 2); //resize the image (if its not already the correct size!) Bitmap bitmap; if (image.Width != newWidth || image.Height != newHeight) bitmap = ImageHelper2.CreateResizedBitmap(image, newWidth, newHeight, image.RawFormat); else bitmap = image; return bitmap; }
internal static Size AdjustImageSizeForNewBaseSize(bool allowEnlargement, IResizeDecoratorSettings s, Size newBaseSize, RotateFlipType rotation, ImageDecoratorContext context) { Size rotatedBaseSize = ImageUtils.IsRotated90(rotation) ? new Size(newBaseSize.Height, newBaseSize.Width) : newBaseSize; if (s.ImageSizeName != ImageSizeName.Custom) { // If a standard image size is being used, fit to that Size sizeBounds = ImageSizeHelper.GetSizeConstraints(s.ImageSizeName); if (!allowEnlargement) { sizeBounds.Width = Math.Min(rotatedBaseSize.Width, sizeBounds.Width); sizeBounds.Height = Math.Min(rotatedBaseSize.Height, sizeBounds.Height); } return ImageUtils.GetScaledImageSize(sizeBounds.Width, sizeBounds.Height, rotatedBaseSize); } else { // If custom size, but we know the base size, preserve // the aspect ratio "skew" (difference in x and y DPI) // and pixel area Size imageSize = s.ImageSize; // Need to get the image size to the non-rotated angle, // because s.BaseSize dimensions are always pre-rotation. // Although ImageSize has not been fully updated for this // decorator yet (that's what we're trying to do here), // the width/height gets flipped immediately when a // rotation is applied, so rotation is already taken // into account. if (ImageUtils.IsRotated90(rotation)) imageSize = new Size(imageSize.Height, imageSize.Width); // If the base size has not been set yet, we have to guess. // This basically means the image was inserted using an older // build of Writer that did not have the crop feature. Ideally // we would use the original image size, but this is expensive // to get from here. It just so happens that newBaseSize works // for now because the crop dialog defaults to the same aspect // ratio as the original image, but if that ever changes this // will break. #if DEBUG if (s.BaseSize == null) { using (Bitmap bitmap = (Bitmap)Bitmap.FromFile(context.SourceImageUri.LocalPath)) { Size size = new Size(Math.Max(1, bitmap.Width / 2), Math.Max(1, bitmap.Height / 2)); Debug.Assert(size.Equals(newBaseSize) || bitmap.Size.Equals(newBaseSize), "Check base size assumptions. Can't use 's.BaseSize ?? newBaseSize', instead must calculate original image size (context.SourceImageUri.LocalPath)."); } } #endif Size baseSize = s.BaseSize ?? newBaseSize; double xFactor = imageSize.Width / (double)baseSize.Width; double yFactor = imageSize.Height / (double)baseSize.Height; newBaseSize = new Size( (int)Math.Round(xFactor * newBaseSize.Width), (int)Math.Round(yFactor * newBaseSize.Height) ); // Need to re-apply the rotation if necessary. if (ImageUtils.IsRotated90(rotation)) newBaseSize = new Size(newBaseSize.Height, newBaseSize.Width); // At this point, newBaseSize has the right aspect ratio; we now // need to scale it so it uses about the same number of pixels // as it did before. double factor = (imageSize.Width * imageSize.Height) / (double)(newBaseSize.Width * newBaseSize.Height); factor = Math.Sqrt(factor); newBaseSize.Width = (int)Math.Round(newBaseSize.Width * factor); newBaseSize.Height = (int)Math.Round(newBaseSize.Height * factor); if (!allowEnlargement) { if (newBaseSize.Width > rotatedBaseSize.Width || newBaseSize.Height > rotatedBaseSize.Height) newBaseSize = ImageUtils.GetScaledImageSize(rotatedBaseSize.Width, rotatedBaseSize.Height, newBaseSize); } return newBaseSize; } }
private void transformImage(PictureBox Frame, RotateFlipType transformType) { if (transformType > 0) Frame.Image.RotateFlip(transformType); }
public void RotateFlip(RotateFlipType rotateFlipType) { Bitmap temp = (Bitmap)_currentBitmap; Bitmap bmap = (Bitmap)temp.Clone(); bmap.RotateFlip(rotateFlipType); _currentBitmap = (Bitmap)bmap.Clone(); }
public string RotateIndexedBmp (Bitmap src, RotateFlipType type) { int pixels_per_byte; switch (src.PixelFormat) { case PixelFormat.Format1bppIndexed: pixels_per_byte = 8; break; case PixelFormat.Format4bppIndexed: pixels_per_byte = 2; break; case PixelFormat.Format8bppIndexed: pixels_per_byte = 1; break; default: throw new Exception("Cannot pass a bitmap of format " + src.PixelFormat + " to RotateIndexedBmp"); } Bitmap test = src.Clone () as Bitmap; test.RotateFlip (type); BitmapData data = null; byte[] pixel_data; try { data = test.LockBits (new Rectangle (0, 0, test.Width, test.Height), ImageLockMode.ReadOnly, test.PixelFormat); int scan_size = (data.Width + pixels_per_byte - 1) / pixels_per_byte; pixel_data = new byte[data.Height * scan_size]; for (int y=0; y < data.Height; y++) { IntPtr src_ptr = (IntPtr)(y * data.Stride + data.Scan0.ToInt64 ()); int dest_offset = y * scan_size; for (int x=0; x < scan_size; x++) pixel_data[dest_offset + x] = Marshal.ReadByte (src_ptr, x); } } finally { if (test != null) { if (data != null) try { test.UnlockBits(data); } catch {} try { test.Dispose(); } catch {} } } if (pixel_data == null) return "--ERROR--"; byte[] hash = new MD5CryptoServiceProvider().ComputeHash (pixel_data); return ByteArrayToString (hash); }
/// <summary> /// Rotate or Flip the icon /// </summary> /// <param name="icon"></param> /// <param name="type">RotateFlipType</param> /// <returns>The new rotated or flipped icon</returns> public static Icon RotateFlip(this Icon icon, RotateFlipType type) { Bitmap bmp = icon.ToBitmap(); bmp.RotateFlip(type); return Icon.FromHandle(bmp.GetHicon()); }
private void VideoNewFrame(object sender, NewFrameEventArgs e) { var nf = NewFrame; var f = e.Frame; if (_requestedToStop || nf==null || f==null) return; if (_lastframeEvent > DateTime.MinValue) { if ((Helper.Now<_nextFrameTarget)) { return; } CalculateFramerates(); } _lastframeEvent = Helper.Now; if (_updateResources) { _updateResources = false; DrawFont.Dispose(); DrawFont = null; ForeBrush.Dispose(); ForeBrush = null; BackBrush.Dispose(); BackBrush = null; SetMaskImage(); RotateFlipType rft; if (Enum.TryParse(CW.Camobject.rotateMode, out rft)) { RotateFlipType = rft; } else { RotateFlipType = RotateFlipType.RotateNoneFlipNone; } } Bitmap bmOrig = null; bool bMotion = false; lock (_sync) { try { bmOrig = ResizeBmOrig(f); if (RotateFlipType != RotateFlipType.RotateNoneFlipNone) { bmOrig.RotateFlip(RotateFlipType); } _width = bmOrig.Width; _height = bmOrig.Height; if (ZPoint == Point.Empty) { ZPoint = new Point(bmOrig.Width / 2, bmOrig.Height / 2); } if (CW.NeedMotionZones) CW.NeedMotionZones = !SetMotionZones(CW.Camobject.detector.motionzones); if (Mask != null) { ApplyMask(bmOrig); } if (CW.Camobject.alerts.active && Plugin != null && Alarm!=null) { bmOrig = RunPlugin(bmOrig); } var bmd = bmOrig.LockBits(new Rectangle(0, 0, bmOrig.Width, bmOrig.Height), ImageLockMode.ReadWrite, bmOrig.PixelFormat); //this converts the image into a windows displayable image so do it regardless using (var lfu = new UnmanagedImage(bmd)) { if (_motionDetector != null) { bMotion = ApplyMotionDetector(lfu); } else { MotionDetected = false; } if (CW.Camobject.settings.FishEyeCorrect) { _feCorrect.Correct(lfu, CW.Camobject.settings.FishEyeFocalLengthPX, CW.Camobject.settings.FishEyeLimit, CW.Camobject.settings.FishEyeScale, ZPoint.X, ZPoint.Y); } if (ZFactor > 1) { var f1 = new ResizeNearestNeighbor(lfu.Width, lfu.Height); var f2 = new Crop(ViewRectangle); try { using (var imgTemp = f2.Apply(lfu)) { f1.Apply(imgTemp, lfu); } } catch (Exception ex) { ErrorHandler?.Invoke(ex.Message); } } } bmOrig.UnlockBits(bmd); PiP(bmOrig); AddTimestamp(bmOrig); } catch (UnsupportedImageFormatException ex) { CW.VideoSourceErrorState = true; CW.VideoSourceErrorMessage = ex.Message; bmOrig?.Dispose(); return; } catch (Exception ex) { bmOrig?.Dispose(); ErrorHandler?.Invoke(ex.Message); return; } if (MotionDetector != null && !CW.Calibrating && MotionDetector.MotionProcessingAlgorithm is BlobCountingObjectsProcessing && !CW.PTZNavigate && CW.Camobject.settings.ptzautotrack) { try { ProcessAutoTracking(); } catch (Exception ex) { ErrorHandler?.Invoke(ex.Message); } } } if (!_requestedToStop) { nf.Invoke(this, new NewFrameEventArgs(bmOrig)); } if (bMotion) { TriggerDetect(this); } }