Imports System.Configuration
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.IO


Public Class GlobalVariables
    Public Shared cstring As String = Desencriptar(My.Settings.ConnString)
    Public Shared VarSession As Boolean
    Public Shared VarContinuar As Boolean
    Public Shared varConfig As Boolean
    Public Shared VarAbrirForm As Boolean
    Public Shared varReporteConsulta As Int32
    Public Shared VarUsuario As String = Nothing
    Public Shared VarEmail As String = Nothing
    Public Shared VarNivel As String = Nothing
    Public Shared VarPassword As String = Nothing
    Public Shared VarNombreForm As String = Nothing

    Public Shared Alerta As Boolean
    Public Shared VarClaveOK As Boolean
    Public Shared VarOpcion As String
    Public Shared varServidorBD As String
    Public Shared varUsuarioAcceso As String
    Public Shared VarUpload As Boolean

    'Variable publica para consultas en reportes de listados
    Public Shared varConsulta As Integer
    Public Shared varCriterioConsulta As String = Nothing
    Public Shared varCriterioConsultaDOS As String = Nothing

    Public Shared VarFromHistoInv As Boolean
    Public Shared VarIDReg As String
    Public Shared EditoCliente As Boolean
    Public Shared EditoInvoice As Boolean

    Public Shared VarOrigen As Boolean

    Public Shared VarOrigenPago As Boolean



    'Reporte universal
    Public Shared ReportPath As String
    Public Shared ReportSQL As String
    Public Shared ReportDs As String
    Public Shared ReportTitle As String



    Public Shared Function Redimensionar(imagen As Image, ancho As Integer, alto As Integer) As Image

        If imagen.Width > imagen.Height Then
            alto = imagen.Height * ancho / imagen.Width
        Else
            ancho = imagen.Width * alto / imagen.Height
        End If

        Dim imagenPhoto As Image = imagen


        Dim bmPhoto As New Bitmap(ancho, alto, PixelFormat.Format24bppRgb)
        bmPhoto.SetResolution(150, 150)
        Dim grPhoto As Graphics = Graphics.FromImage(bmPhoto)
        grPhoto.SmoothingMode = SmoothingMode.AntiAlias
        grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic
        grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality
        grPhoto.DrawImage(imagenPhoto, New Rectangle(0, 0, ancho, alto), 0, 0, imagen.Width, imagen.Height,
            GraphicsUnit.Pixel)

        Dim mm As New MemoryStream()
        bmPhoto.Save(mm, System.Drawing.Imaging.ImageFormat.Jpeg)
        imagen.Dispose()
        imagenPhoto.Dispose()
        bmPhoto.Dispose()
        grPhoto.Dispose()
        Return ByteArrayToImage(mm.GetBuffer())

        'Dim img As Image = Redimensionar(PictureBox1.Image, 1200, 900)   <--- asi llamo la fucion
        'Dim img As Image = Redimensionar(PictureBox1.Image, 120, 90)
        'img.Save("c:\_img\" & nvoArchivo)  <--- asi la guardo temporalmente.
    End Function

    Public Shared Function ByteArrayToImage(arregloDeBytes As Byte()) As Image
        Dim ms As New MemoryStream(arregloDeBytes)
        Dim imagen As Image = Image.FromStream(ms)
        Return imagen
    End Function
End Class

