示例#1
0
        //Image resizing
        public static System.Drawing.Image ResizeImage(int maxWidth, int maxHeight, System.Drawing.Image Image)
        {
            int width = Image.Width;
            int height = Image.Height;
            if (width > maxWidth || height > maxHeight)
            {
                //The flips are in here to prevent any embedded image thumbnails -- usually from cameras
                //from displaying as the thumbnail image later, in other words, we want a clean
                //resize, not a grainy one.
                Image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipX);
                Image.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipX);

                float ratio = 0;
                if (width > height)
                {
                    ratio = (float)width / (float)height;
                    width = maxWidth;
                    height = Convert.ToInt32(Math.Round((float)width / ratio));
                }
                else
                {
                    ratio = (float)height / (float)width;
                    height = maxHeight;
                    width = Convert.ToInt32(Math.Round((float)height / ratio));
                }

                //return the resized image
                return Image.GetThumbnailImage(width, height, null, IntPtr.Zero);
            }

            //return the original resized image
            return Image;
        }
示例#2
0
        /// <summary>
        /// 转换Bitmap到Image(WPF)
        /// </summary>
        public static BitmapImage ConvertBitmapToSource(System.Drawing.Bitmap b,
            System.Drawing.RotateFlipType t = System.Drawing.RotateFlipType.Rotate90FlipX)
        {
            b.RotateFlip(t);
            MemoryStream ms = new MemoryStream();
            b.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);

            BitmapImage bmi = new BitmapImage();
            bmi.BeginInit();
            bmi.StreamSource = new MemoryStream(ms.ToArray());
            bmi.EndInit();
            ms.Close();

            return bmi;
        }
示例#3
0
        void DrawPng(XGraphics gfx, double _indRow, double _indCol, System.Drawing.Image _imgThumb)
        {
            // Si l'image est plus large que haute, on la fait tourner
            if (_imgThumb.Width > _imgThumb.Height)
            {
                _imgThumb.RotateFlip(RotateFlipType.Rotate270FlipNone);
            }

            XImage image = XImage.FromGdiPlusImage(_imgThumb);
            double dx = (80 * _indCol) + 33;
            double dy = (113 * _indRow) + 28;
            double width = 57;
            double height = 80;
            gfx.DrawImage(image, dx, dy, width, height);
        }
示例#4
0
/*        public void RenderBackgroundList(SpriteBatch sprite, int xShift, int yShift, bool front)
        {
            if (!((ApplicationSettings.visibleTypes & ItemTypes.Backgrounds) == ItemTypes.Backgrounds)) return;
            foreach (BackgroundInstance bg in boardItems.Backgrounds)
                if (bg.front == front && parent.IsItemInRange(bg.X, bg.Y, bg.Width, bg.Height,xShift - bg.Origin.X,yShift - bg.Origin.Y))
                    bg.Draw(sprite, bg.GetColor(ApplicationSettings.editedTypes, selectedLayerIndex, bg.Selected), xShift, yShift);
        }*/

        public System.Drawing.Bitmap ResizeImage(System.Drawing.Bitmap FullsizeImage, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
        {
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
            FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

            if (OnlyResizeIfWider)
            {
                if (FullsizeImage.Width <= NewWidth)
                {
                    NewWidth = FullsizeImage.Width;
                }
            }

            int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;
            if (NewHeight > MaxHeight)
            {
                NewWidth = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;
                NewHeight = MaxHeight;
            }
            System.Drawing.Bitmap NewImage = (System.Drawing.Bitmap)FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);
            return NewImage;
        }
示例#5
0
 //      private static void ReColor (P1, P2: Pointer; C: Byte)
 //      {
 //      {
 //        asm
 //              push    ds
 //              push    es
 //              lds     si, P1
 //              les     di, P2
 //              cld
 //              mov     cx, Buffers.H
 //      1:     push    cx
 //              mov     cx, Buffers.W
 //      2:     lodsb
 //              cmp     al, $10
 //              jbe     3
 //              &&     al, 07h
 //              add     al, C
 //
 //      3:     stosb
 //              loop    2
 //              pop     cx
 //              loop    1
 //              pop     es
 //              pop     ds
 //        }
 //      }
 //      }
 //      private static void ReColor2 (P1, P2: Pointer; C1, C2: Byte)
 //      {
 //      {
 //        asm
 //              push    ds
 //              push    es
 //              lds     si, P1
 //              les     di, P2
 //              cld
 //              mov     cx, Buffers.H
 //      1:     push    cx
 //              mov     cx, Buffers.W
 //      2:     lodsb
 //              cmp     al, $10
 //              jbe     3
 //              &&     al, 0Fh
 //              cmp     al, 8
 //              jb      UseC1
 //              &&     al, 7
 //              add     al, C2
 //              jmp     3
 //      UseC1:
 //              add     al, C1
 //
 //      3:     stosb
 //              loop    2
 //              pop     cx
 //              loop    1
 //              pop     es
 //              pop     ds
 //        }
 //      }
 //      }
 //      private static void Replace(P1, P2: Pointer; N1, N2: Byte)
 //      {
 //      {
 //        asm
 //              push    ds
 //              push    es
 //              lds     si, P1
 //              les     di, P2
 //              cld
 //              mov     cx, Buffers.H
 //      1:     push    cx
 //              mov     cx, Buffers.W
 //      2:     lodsb
 //              cmp     al, N1
 //              jnz     3
 //              mov     al, N2
 //      3:     stosb
 //              loop    2
 //              pop     cx
 //              loop    1
 //              pop     es
 //              pop     ds
 //        }
 //      }
 //      }
 public static void Mirror(System.Drawing.Bitmap from, ref System.Drawing.Bitmap to)
 {
     if (from == null)
     return;
      from.RotateFlip(RotateFlipType.Rotate180FlipY);
      to = from.Clone() as Bitmap;
 }
示例#6
0
 public void Rotacionar(System.Drawing.Image image, string caminhoImagemDestino, RotateFlipType angulo)
 {
     image.RotateFlip(angulo);
     image.Save(caminhoImagemDestino, ImageFormat.Jpeg);
 }
示例#7
0
 public System.Drawing.Image Rotacionar(System.Drawing.Image image, RotateFlipType angulo)
 {
     image.RotateFlip(angulo);
     return image;
 }
示例#8
0
 private void TryRotateImage(System.Drawing.Image inputImage)
 {
     try
     {
         if (inputImage.PropertyIdList.Contains(0x0112))
         {
             var pro = inputImage.GetPropertyItem(0x0112);
             if (pro != null && pro.Value[0] == 6 && pro.Value[1] == 0)
             {
                 inputImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Error("ImageService.TryRotateImage", ex);
     }
 }