Truyện hay
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.

Truyện hayĐăng Nhập

truyenhay cung cấp truyện và chia sẻ truyen hay - truyện hay, các thể loại truyện 18+, sac hiep, tien hiep, di hiep đã hoàn thành full


descriptionThủ tục co ảnh VB EmptyThủ tục co ảnh VB

more_horiz

Code:

Public Sub Resize(newWidth As Integer, newHeight As Integer)
   If newWidth <> 0 AndAlso newHeight <> 0 Then
      Dim temp As Bitmap = DirectCast(_currentBitmap, Bitmap)
      Dim bmap As New Bitmap(newWidth, newHeight, temp.PixelFormat)

      Dim nWidthFactor As Double = DirectCast(temp.Width, Double) / DirectCast(newWidth, Double)
      Dim nHeightFactor As Double = DirectCast(temp.Height, Double) / DirectCast(newHeight, Double)

      Dim fx As Double, fy As Double, nx As Double, ny As Double
      Dim cx As Integer, cy As Integer, fr_x As Integer, fr_y As Integer
      Dim color1 As New Color()
      Dim color2 As New Color()
      Dim color3 As New Color()
      Dim color4 As New Color()
      Dim nRed As Byte, nGreen As Byte, nBlue As Byte

      Dim bp1 As Byte, bp2 As Byte

      Dim x As Integer = 0
      While x < bmap.Width
         Dim y As Integer = 0
         While y < bmap.Height

            fr_x = CInt(Math.Floor(x * nWidthFactor))
            fr_y = CInt(Math.Floor(y * nHeightFactor))
            cx = fr_x + 1
            If cx >= temp.Width Then
               cx = fr_x
            End If
            cy = fr_y + 1
            If cy >= temp.Height Then
               cy = fr_y
            End If
            fx = x * nWidthFactor - fr_x
            fy = y * nHeightFactor - fr_y
            nx = 1.0 - fx
            ny = 1.0 - fy

            color1 = temp.GetPixel(fr_x, fr_y)
            color2 = temp.GetPixel(cx, fr_y)
            color3 = temp.GetPixel(fr_x, cy)
            color4 = temp.GetPixel(cx, cy)

            ' Blue
            bp1 = DirectCast(nx * color1.B + fx * color2.B, Byte)

            bp2 = DirectCast(nx * color3.B + fx * color4.B, Byte)

            nBlue = DirectCast(ny * DirectCast(bp1, Double) + fy * DirectCast(bp2, Double), Byte)

            ' Green
            bp1 = DirectCast(nx * color1.G + fx * color2.G, Byte)

            bp2 = DirectCast(nx * color3.G + fx * color4.G, Byte)

            nGreen = DirectCast(ny * DirectCast(bp1, Double) + fy * DirectCast(bp2, Double), Byte)

            ' Red
            bp1 = DirectCast(nx * color1.R + fx * color2.R, Byte)

            bp2 = DirectCast(nx * color3.R + fx * color4.R, Byte)

            nRed = DirectCast(ny * DirectCast(bp1, Double) + fy * DirectCast(bp2, Double), Byte)

            bmap.SetPixel(x, y, System.Drawing.Color.FromArgb(255, nRed, nGreen, nBlue))
            System.Threading.Interlocked.Increment(y)
         End While
         System.Threading.Interlocked.Increment(x)
      End While
      _currentBitmap = DirectCast(bmap.Clone(), Bitmap)
   End If
End Sub

descriptionThủ tục co ảnh VB EmptyRe: Thủ tục co ảnh VB

more_horiz
Public Sub Resize(newWidth As Integer, newHeight As Integer)
If newWidth <> 0 AndAlso newHeight <> 0 Then
Dim temp As Bitmap = DirectCast(_currentBitmap, Bitmap)
Dim bmap As New Bitmap(newWidth, newHeight, temp.PixelFormat)

Dim nWidthFactor As Double = DirectCast(temp.Width, Double) / DirectCast(newWidth, Double)
Dim nHeightFactor As Double = DirectCast(temp.Height, Double) / DirectCast(newHeight, Double)

Dim fx As Double, fy As Double, nx As Double, ny As Double
Dim cx As Integer, cy As Integer, fr_x As Integer, fr_y As Integer
Dim color1 As New Color()
Dim color2 As New Color()
Dim color3 As New Color()
Dim color4 As New Color()
Dim nRed As Byte, nGreen As Byte, nBlue As Byte

Dim bp1 As Byte, bp2 As Byte

Dim x As Integer = 0
While x < bmap.Width
Dim y As Integer = 0
While y < bmap.Height

fr_x = CInt(Math.Floor(x * nWidthFactor))
fr_y = CInt(Math.Floor(y * nHeightFactor))
cx = fr_x + 1
If cx >= temp.Width Then
cx = fr_x
End If
cy = fr_y + 1
If cy >= temp.Height Then
cy = fr_y
End If
fx = x * nWidthFactor - fr_x
fy = y * nHeightFactor - fr_y
nx = 1.0 - fx
ny = 1.0 - fy

color1 = temp.GetPixel(fr_x, fr_y)
color2 = temp.GetPixel(cx, fr_y)
color3 = temp.GetPixel(fr_x, cy)
color4 = temp.GetPixel(cx, cy)

' Blue
bp1 = DirectCast(nx * color1.B + fx * color2.B, Byte)

bp2 = DirectCast(nx * color3.B + fx * color4.B, Byte)

nBlue = DirectCast(ny * DirectCast(bp1, Double) + fy * DirectCast(bp2, Double), Byte)

' Green
bp1 = DirectCast(nx * color1.G + fx * color2.G, Byte)

bp2 = DirectCast(nx * color3.G + fx * color4.G, Byte)

nGreen = DirectCast(ny * DirectCast(bp1, Double) + fy * DirectCast(bp2, Double), Byte)

' Red
bp1 = DirectCast(nx * color1.R + fx * color2.R, Byte)

bp2 = DirectCast(nx * color3.R + fx * color4.R, Byte)

nRed = DirectCast(ny * DirectCast(bp1, Double) + fy * DirectCast(bp2, Double), Byte)

bmap.SetPixel(x, y, System.Drawing.Color.FromArgb(255, nRed, nGreen, nBlue))
System.Threading.Interlocked.Increment(y)
End While
System.Threading.Interlocked.Increment(x)
End While
_currentBitmap = DirectCast(bmap.Clone(), Bitmap)
End If
End Sub
privacy_tip Permissions in this forum:
Bạn không có quyền trả lời bài viết
power_settings_newLogin to reply