تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
مساعدة في حفظ الصورة
#10
كود :
#Region " ResizeImage "
  Public Overloads Shared Function ResizeImage(SourceImage As Drawing.Image, TargetWidth As Int32, TargetHeight As Int32) As Drawing.Bitmap
      Dim bmSource = New Drawing.Bitmap(SourceImage)

      Return ResizeImage(bmSource, TargetWidth, TargetHeight)
  End Function

  Public Overloads Shared Function ResizeImage(bmSource As Drawing.Bitmap, TargetWidth As Int32, TargetHeight As Int32) As Drawing.Bitmap
      Dim bmDest As New Drawing.Bitmap(TargetWidth, TargetHeight, Drawing.Imaging.PixelFormat.Format32bppArgb)

      Dim nSourceAspectRatio = bmSource.Width / bmSource.Height
      Dim nDestAspectRatio = bmDest.Width / bmDest.Height

      Dim NewX = 0
      Dim NewY = 0
      Dim NewWidth = bmDest.Width
      Dim NewHeight = bmDest.Height

      If nDestAspectRatio = nSourceAspectRatio Then
          'same ratio
      ElseIf nDestAspectRatio > nSourceAspectRatio Then
          'Source is taller
          NewWidth = Convert.ToInt32(Math.Floor(nSourceAspectRatio * NewHeight))
          NewX = Convert.ToInt32(Math.Floor((bmDest.Width - NewWidth) / 2))
      Else
          'Source is wider
          NewHeight = Convert.ToInt32(Math.Floor((1 / nSourceAspectRatio) * NewWidth))
          NewY = Convert.ToInt32(Math.Floor((bmDest.Height - NewHeight) / 2))
      End If

      Using grDest = Drawing.Graphics.FromImage(bmDest)
          With grDest
              .CompositingQuality = Drawing.Drawing2D.CompositingQuality.HighQuality
              .InterpolationMode = Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
              .PixelOffsetMode = Drawing.Drawing2D.PixelOffsetMode.HighQuality
              .SmoothingMode = Drawing.Drawing2D.SmoothingMode.AntiAlias
              .CompositingMode = Drawing.Drawing2D.CompositingMode.SourceOver

              .DrawImage(bmSource, NewX, NewY, NewWidth, NewHeight)
          End With
      End Using

      Return bmDest
  End Function
#End Region


استاذي العزيز viv 
لقد حاولت العمل بهذا الكود ولكن من دون فائده فلم افهمه جيدا
الرد }}}
تم الشكر بواسطة:


الردود في هذا الموضوع
مساعدة في حفظ الصورة - بواسطة alshandodi - 10-11-19, 10:09 AM
RE: مساعدة في حفظ الصورة - بواسطة AbdoDabak - 10-11-19, 11:55 AM
RE: مساعدة في حفظ الصورة - بواسطة alshandodi - 10-11-19, 02:56 PM
RE: مساعدة في حفظ الصورة - بواسطة alshandodi - 11-11-19, 07:21 AM
RE: مساعدة في حفظ الصورة - بواسطة 3booody - 11-11-19, 04:04 PM
RE: مساعدة في حفظ الصورة - بواسطة alshandodi - 11-11-19, 08:36 PM
RE: مساعدة في حفظ الصورة - بواسطة asemshahen5 - 12-11-19, 07:13 AM
RE: مساعدة في حفظ الصورة - بواسطة viv - 21-12-19, 12:26 PM
RE: مساعدة في حفظ الصورة - بواسطة alshandodi - 26-01-20, 08:24 AM


التنقل السريع :


يقوم بقرائة الموضوع: