Bonjour
La fonction qui modifie une image : ModifyImage
La fonction qui affiche l'image : DisplayImage
Cordialement,
Sébastien Pertus
Private Sub DisplayImage(ByVal imageID As Integer, ByVal
width As Integer, ByVal height As Integer, ByVal thumbnail
As Boolean)
Try
Dim image As Byte()
Dim dr As SqlDataReader
dr = RetrouverImageFromBase(imageID)
If dr.Read() Then
context.Response.ContentType = dr
("IMG_contenttype").ToString()
image = dr("IMG_filedata")
image = ImageUtility.ModifyImage(image, width,
height, dr("IMG_contenttype").ToString(), thumbnail)
context.Response.BinaryWrite(image)
End If
Catch ex As Exception
End Try
Public Shared Function ModifyImage(ByVal original() As
Byte, ByVal width As Integer, ByVal height As Integer,
ByVal contentType As String, ByVal isThumbNail As Boolean)
As Byte()
Dim stream As New MemoryStream(original)
Dim bmp As Bitmap = CType(Image.FromStream(stream),
Bitmap)
If width = -1 And height = -1 Then
width = bmp.Width
height = bmp.Height
ElseIf width > -1 And width > bmp.Width Then
width = bmp.Width
height = bmp.Height
ElseIf height > -1 And height > bmp.Height Then
width = bmp.Width
height = bmp.Height
Else
If width = -1 Then
width = Fix(System.Convert.ToDouble(height) /
System.Convert.ToDouble(bmp.Height) *
System.Convert.ToDouble(bmp.Width))
End If
If height = -1 Then
height = Fix(System.Convert.ToDouble(width) /
System.Convert.ToDouble(bmp.Width) *
System.Convert.ToDouble(bmp.Height))
End If
End If
Dim thumbBmp As New Bitmap(bmp, width, height)
thumbBmp.Palette = GetTransparentColorPalette(bmp)
stream = New MemoryStream
If contentType.ToLower().EndsWith("pjpeg") Then
If isThumbNail Then
stream = SaveJpgWithCompression(thumbBmp, 40)
Else
thumbBmp.Save(stream, ImageFormat.Jpeg)
End If
Else
thumbBmp.Save(stream, ImageFormat.Gif)
End If
thumbBmp.Dispose()
bmp.Dispose()
Return stream.GetBuffer()
End Function
Bonjour
La fonction qui modifie une image : ModifyImage
La fonction qui affiche l'image : DisplayImage
Cordialement,
Sébastien Pertus
Private Sub DisplayImage(ByVal imageID As Integer, ByVal
width As Integer, ByVal height As Integer, ByVal thumbnail
As Boolean)
Try
Dim image As Byte()
Dim dr As SqlDataReader
dr = RetrouverImageFromBase(imageID)
If dr.Read() Then
context.Response.ContentType = dr
("IMG_contenttype").ToString()
image = dr("IMG_filedata")
image = ImageUtility.ModifyImage(image, width,
height, dr("IMG_contenttype").ToString(), thumbnail)
context.Response.BinaryWrite(image)
End If
Catch ex As Exception
End Try
Public Shared Function ModifyImage(ByVal original() As
Byte, ByVal width As Integer, ByVal height As Integer,
ByVal contentType As String, ByVal isThumbNail As Boolean)
As Byte()
Dim stream As New MemoryStream(original)
Dim bmp As Bitmap = CType(Image.FromStream(stream),
Bitmap)
If width = -1 And height = -1 Then
width = bmp.Width
height = bmp.Height
ElseIf width > -1 And width > bmp.Width Then
width = bmp.Width
height = bmp.Height
ElseIf height > -1 And height > bmp.Height Then
width = bmp.Width
height = bmp.Height
Else
If width = -1 Then
width = Fix(System.Convert.ToDouble(height) /
System.Convert.ToDouble(bmp.Height) *
System.Convert.ToDouble(bmp.Width))
End If
If height = -1 Then
height = Fix(System.Convert.ToDouble(width) /
System.Convert.ToDouble(bmp.Width) *
System.Convert.ToDouble(bmp.Height))
End If
End If
Dim thumbBmp As New Bitmap(bmp, width, height)
thumbBmp.Palette = GetTransparentColorPalette(bmp)
stream = New MemoryStream
If contentType.ToLower().EndsWith("pjpeg") Then
If isThumbNail Then
stream = SaveJpgWithCompression(thumbBmp, 40)
Else
thumbBmp.Save(stream, ImageFormat.Jpeg)
End If
Else
thumbBmp.Save(stream, ImageFormat.Gif)
End If
thumbBmp.Dispose()
bmp.Dispose()
Return stream.GetBuffer()
End Function
Bonjour
La fonction qui modifie une image : ModifyImage
La fonction qui affiche l'image : DisplayImage
Cordialement,
Sébastien Pertus
Private Sub DisplayImage(ByVal imageID As Integer, ByVal
width As Integer, ByVal height As Integer, ByVal thumbnail
As Boolean)
Try
Dim image As Byte()
Dim dr As SqlDataReader
dr = RetrouverImageFromBase(imageID)
If dr.Read() Then
context.Response.ContentType = dr
("IMG_contenttype").ToString()
image = dr("IMG_filedata")
image = ImageUtility.ModifyImage(image, width,
height, dr("IMG_contenttype").ToString(), thumbnail)
context.Response.BinaryWrite(image)
End If
Catch ex As Exception
End Try
Public Shared Function ModifyImage(ByVal original() As
Byte, ByVal width As Integer, ByVal height As Integer,
ByVal contentType As String, ByVal isThumbNail As Boolean)
As Byte()
Dim stream As New MemoryStream(original)
Dim bmp As Bitmap = CType(Image.FromStream(stream),
Bitmap)
If width = -1 And height = -1 Then
width = bmp.Width
height = bmp.Height
ElseIf width > -1 And width > bmp.Width Then
width = bmp.Width
height = bmp.Height
ElseIf height > -1 And height > bmp.Height Then
width = bmp.Width
height = bmp.Height
Else
If width = -1 Then
width = Fix(System.Convert.ToDouble(height) /
System.Convert.ToDouble(bmp.Height) *
System.Convert.ToDouble(bmp.Width))
End If
If height = -1 Then
height = Fix(System.Convert.ToDouble(width) /
System.Convert.ToDouble(bmp.Width) *
System.Convert.ToDouble(bmp.Height))
End If
End If
Dim thumbBmp As New Bitmap(bmp, width, height)
thumbBmp.Palette = GetTransparentColorPalette(bmp)
stream = New MemoryStream
If contentType.ToLower().EndsWith("pjpeg") Then
If isThumbNail Then
stream = SaveJpgWithCompression(thumbBmp, 40)
Else
thumbBmp.Save(stream, ImageFormat.Jpeg)
End If
Else
thumbBmp.Save(stream, ImageFormat.Gif)
End If
thumbBmp.Dispose()
bmp.Dispose()
Return stream.GetBuffer()
End Function
GetTransparentColorPalette
GetTransparentColorPalette
GetTransparentColorPalette
-----Message d'origine-----
Autre petite question
Ca me dit que GetTransparentColorPalette n'est pas défini
On Thu, 19 Aug 2004 07:57:43 -0700, "Sebastien Pertus"
wrote:GetTransparentColorPalette
.
-----Message d'origine-----
Autre petite question
Ca me dit que GetTransparentColorPalette n'est pas défini
On Thu, 19 Aug 2004 07:57:43 -0700, "Sebastien Pertus"
<sebastien@_REMOVETHIS_midiway.fr> wrote:
GetTransparentColorPalette
.
-----Message d'origine-----
Autre petite question
Ca me dit que GetTransparentColorPalette n'est pas défini
On Thu, 19 Aug 2004 07:57:43 -0700, "Sebastien Pertus"
wrote:GetTransparentColorPalette
.
Je l'avais oublié celle là :)
Tu auras aussi besoin de SaveJpgWithCompression
voilà les deux fonctions :
Private Shared Function GetTransparentColorPalette(ByVal
original As Bitmap) As ColorPalette
Dim testColor As Color
Dim newColor As Color
Dim pal As ColorPalette = original.Palette
Dim i As Integer
For i = 0 To (pal.Entries.Length - 1) - 1
testColor = pal.Entries(i)
If testColor.A = 0 Then
newColor = Color.FromArgb(0, testColor)
pal.Entries(i) = newColor
End If
Next i
Return pal
End Function
Private Overloads Shared Function SaveJpgWithCompression
(ByVal original As Image, ByVal compression As Long) As
MemoryStream
Dim ms As New MemoryStream
Dim eps As New EncoderParameters(1)
eps.Param(0) = New EncoderParameter(Encoder.Quality,
compression)
Dim ici As ImageCodecInfo = GetEncoderInfo
("image/jpeg")
original.Save(ms, ici, eps)
Return ms
End Function
Sébastien-----Message d'origine-----
Autre petite question
Ca me dit que GetTransparentColorPalette n'est pas défini
On Thu, 19 Aug 2004 07:57:43 -0700, "Sebastien Pertus"
wrote:GetTransparentColorPalette
.
Je l'avais oublié celle là :)
Tu auras aussi besoin de SaveJpgWithCompression
voilà les deux fonctions :
Private Shared Function GetTransparentColorPalette(ByVal
original As Bitmap) As ColorPalette
Dim testColor As Color
Dim newColor As Color
Dim pal As ColorPalette = original.Palette
Dim i As Integer
For i = 0 To (pal.Entries.Length - 1) - 1
testColor = pal.Entries(i)
If testColor.A = 0 Then
newColor = Color.FromArgb(0, testColor)
pal.Entries(i) = newColor
End If
Next i
Return pal
End Function
Private Overloads Shared Function SaveJpgWithCompression
(ByVal original As Image, ByVal compression As Long) As
MemoryStream
Dim ms As New MemoryStream
Dim eps As New EncoderParameters(1)
eps.Param(0) = New EncoderParameter(Encoder.Quality,
compression)
Dim ici As ImageCodecInfo = GetEncoderInfo
("image/jpeg")
original.Save(ms, ici, eps)
Return ms
End Function
Sébastien
-----Message d'origine-----
Autre petite question
Ca me dit que GetTransparentColorPalette n'est pas défini
On Thu, 19 Aug 2004 07:57:43 -0700, "Sebastien Pertus"
<sebastien@_REMOVETHIS_midiway.fr> wrote:
GetTransparentColorPalette
.
Je l'avais oublié celle là :)
Tu auras aussi besoin de SaveJpgWithCompression
voilà les deux fonctions :
Private Shared Function GetTransparentColorPalette(ByVal
original As Bitmap) As ColorPalette
Dim testColor As Color
Dim newColor As Color
Dim pal As ColorPalette = original.Palette
Dim i As Integer
For i = 0 To (pal.Entries.Length - 1) - 1
testColor = pal.Entries(i)
If testColor.A = 0 Then
newColor = Color.FromArgb(0, testColor)
pal.Entries(i) = newColor
End If
Next i
Return pal
End Function
Private Overloads Shared Function SaveJpgWithCompression
(ByVal original As Image, ByVal compression As Long) As
MemoryStream
Dim ms As New MemoryStream
Dim eps As New EncoderParameters(1)
eps.Param(0) = New EncoderParameter(Encoder.Quality,
compression)
Dim ici As ImageCodecInfo = GetEncoderInfo
("image/jpeg")
original.Save(ms, ici, eps)
Return ms
End Function
Sébastien-----Message d'origine-----
Autre petite question
Ca me dit que GetTransparentColorPalette n'est pas défini
On Thu, 19 Aug 2004 07:57:43 -0700, "Sebastien Pertus"
wrote:GetTransparentColorPalette
.
-----Message d'origine-----
Merci
Cette façon de faire génère un fichier sur disque. Est-ce
le faire sans générer de fichier sur disque ?
On Thu, 19 Aug 2004 09:21:23 -0700, "Sebastien Pertus"
wrote:Je l'avais oublié celle là :)
Tu auras aussi besoin de SaveJpgWithCompression
voilà les deux fonctions :
Private Shared Function GetTransparentColorPalette
original As Bitmap) As ColorPalette
Dim testColor As Color
Dim newColor As Color
Dim pal As ColorPalette = original.Palette
Dim i As Integer
For i = 0 To (pal.Entries.Length - 1) - 1
testColor = pal.Entries(i)
If testColor.A = 0 Then
newColor = Color.FromArgb(0, testColor)
pal.Entries(i) = newColor
End If
Next i
Return pal
End Function
Private Overloads Shared Function
(ByVal original As Image, ByVal compression As Long) As
MemoryStream
Dim ms As New MemoryStream
Dim eps As New EncoderParameters(1)
eps.Param(0) = New EncoderParameter(Encoder.Quality,
compression)
Dim ici As ImageCodecInfo = GetEncoderInfo
("image/jpeg")
original.Save(ms, ici, eps)
Return ms
End Function
Sébastien-----Message d'origine-----
Autre petite question
Ca me dit que GetTransparentColorPalette n'est pas
On Thu, 19 Aug 2004 07:57:43 -0700, "Sebastien Pertus"
wrote:GetTransparentColorPalette
.
.
-----Message d'origine-----
Merci
Cette façon de faire génère un fichier sur disque. Est-ce
le faire sans générer de fichier sur disque ?
On Thu, 19 Aug 2004 09:21:23 -0700, "Sebastien Pertus"
<Sebastien@8REMOVETHIS8Midiway.Fr> wrote:
Je l'avais oublié celle là :)
Tu auras aussi besoin de SaveJpgWithCompression
voilà les deux fonctions :
Private Shared Function GetTransparentColorPalette
original As Bitmap) As ColorPalette
Dim testColor As Color
Dim newColor As Color
Dim pal As ColorPalette = original.Palette
Dim i As Integer
For i = 0 To (pal.Entries.Length - 1) - 1
testColor = pal.Entries(i)
If testColor.A = 0 Then
newColor = Color.FromArgb(0, testColor)
pal.Entries(i) = newColor
End If
Next i
Return pal
End Function
Private Overloads Shared Function
(ByVal original As Image, ByVal compression As Long) As
MemoryStream
Dim ms As New MemoryStream
Dim eps As New EncoderParameters(1)
eps.Param(0) = New EncoderParameter(Encoder.Quality,
compression)
Dim ici As ImageCodecInfo = GetEncoderInfo
("image/jpeg")
original.Save(ms, ici, eps)
Return ms
End Function
Sébastien
-----Message d'origine-----
Autre petite question
Ca me dit que GetTransparentColorPalette n'est pas
On Thu, 19 Aug 2004 07:57:43 -0700, "Sebastien Pertus"
<sebastien@_REMOVETHIS_midiway.fr> wrote:
GetTransparentColorPalette
.
.
-----Message d'origine-----
Merci
Cette façon de faire génère un fichier sur disque. Est-ce
le faire sans générer de fichier sur disque ?
On Thu, 19 Aug 2004 09:21:23 -0700, "Sebastien Pertus"
wrote:Je l'avais oublié celle là :)
Tu auras aussi besoin de SaveJpgWithCompression
voilà les deux fonctions :
Private Shared Function GetTransparentColorPalette
original As Bitmap) As ColorPalette
Dim testColor As Color
Dim newColor As Color
Dim pal As ColorPalette = original.Palette
Dim i As Integer
For i = 0 To (pal.Entries.Length - 1) - 1
testColor = pal.Entries(i)
If testColor.A = 0 Then
newColor = Color.FromArgb(0, testColor)
pal.Entries(i) = newColor
End If
Next i
Return pal
End Function
Private Overloads Shared Function
(ByVal original As Image, ByVal compression As Long) As
MemoryStream
Dim ms As New MemoryStream
Dim eps As New EncoderParameters(1)
eps.Param(0) = New EncoderParameter(Encoder.Quality,
compression)
Dim ici As ImageCodecInfo = GetEncoderInfo
("image/jpeg")
original.Save(ms, ici, eps)
Return ms
End Function
Sébastien-----Message d'origine-----
Autre petite question
Ca me dit que GetTransparentColorPalette n'est pas
On Thu, 19 Aug 2004 07:57:43 -0700, "Sebastien Pertus"
wrote:GetTransparentColorPalette
.
.
Non, erreur :)
Cette façon génère un flux de donnée qu'il expose
dirctement au navigateur (context.Response.BinaryWrite
(image))
Il n'y a aucun fichier sur ton disque :)
Si tu te réfères à la compression :
"original.Save(ms, ici, eps)"
Le fichier compressé est sauvegardé dans "ms" qui est un
MemoryStream , un flux d'octet en mémoire et non pas un
fichire sur le disque.
C'est ce que j'utilise pour un de mes sites.
Toutes les images sont en base de données, et aucune sur
le disque, même quand on les affiche.
Aucune trace.
Sébastien-----Message d'origine-----
Merci
Cette façon de faire génère un fichier sur disque. Est-ce
possible dele faire sans générer de fichier sur disque ?
On Thu, 19 Aug 2004 09:21:23 -0700, "Sebastien Pertus"
wrote:Je l'avais oublié celle là :)
Tu auras aussi besoin de SaveJpgWithCompression
voilà les deux fonctions :
Private Shared Function GetTransparentColorPalette
(ByValoriginal As Bitmap) As ColorPalette
Dim testColor As Color
Dim newColor As Color
Dim pal As ColorPalette = original.Palette
Dim i As Integer
For i = 0 To (pal.Entries.Length - 1) - 1
testColor = pal.Entries(i)
If testColor.A = 0 Then
newColor = Color.FromArgb(0, testColor)
pal.Entries(i) = newColor
End If
Next i
Return pal
End Function
Private Overloads Shared Function
SaveJpgWithCompression(ByVal original As Image, ByVal compression As Long) As
MemoryStream
Dim ms As New MemoryStream
Dim eps As New EncoderParameters(1)
eps.Param(0) = New EncoderParameter(Encoder.Quality,
compression)
Dim ici As ImageCodecInfo = GetEncoderInfo
("image/jpeg")
original.Save(ms, ici, eps)
Return ms
End Function
Sébastien-----Message d'origine-----
Autre petite question
Ca me dit que GetTransparentColorPalette n'est pas
défini
On Thu, 19 Aug 2004 07:57:43 -0700, "Sebastien Pertus"
wrote:GetTransparentColorPalette
.
.
Non, erreur :)
Cette façon génère un flux de donnée qu'il expose
dirctement au navigateur (context.Response.BinaryWrite
(image))
Il n'y a aucun fichier sur ton disque :)
Si tu te réfères à la compression :
"original.Save(ms, ici, eps)"
Le fichier compressé est sauvegardé dans "ms" qui est un
MemoryStream , un flux d'octet en mémoire et non pas un
fichire sur le disque.
C'est ce que j'utilise pour un de mes sites.
Toutes les images sont en base de données, et aucune sur
le disque, même quand on les affiche.
Aucune trace.
Sébastien
-----Message d'origine-----
Merci
Cette façon de faire génère un fichier sur disque. Est-ce
possible de
le faire sans générer de fichier sur disque ?
On Thu, 19 Aug 2004 09:21:23 -0700, "Sebastien Pertus"
<Sebastien@8REMOVETHIS8Midiway.Fr> wrote:
Je l'avais oublié celle là :)
Tu auras aussi besoin de SaveJpgWithCompression
voilà les deux fonctions :
Private Shared Function GetTransparentColorPalette
(ByVal
original As Bitmap) As ColorPalette
Dim testColor As Color
Dim newColor As Color
Dim pal As ColorPalette = original.Palette
Dim i As Integer
For i = 0 To (pal.Entries.Length - 1) - 1
testColor = pal.Entries(i)
If testColor.A = 0 Then
newColor = Color.FromArgb(0, testColor)
pal.Entries(i) = newColor
End If
Next i
Return pal
End Function
Private Overloads Shared Function
SaveJpgWithCompression
(ByVal original As Image, ByVal compression As Long) As
MemoryStream
Dim ms As New MemoryStream
Dim eps As New EncoderParameters(1)
eps.Param(0) = New EncoderParameter(Encoder.Quality,
compression)
Dim ici As ImageCodecInfo = GetEncoderInfo
("image/jpeg")
original.Save(ms, ici, eps)
Return ms
End Function
Sébastien
-----Message d'origine-----
Autre petite question
Ca me dit que GetTransparentColorPalette n'est pas
défini
On Thu, 19 Aug 2004 07:57:43 -0700, "Sebastien Pertus"
<sebastien@_REMOVETHIS_midiway.fr> wrote:
GetTransparentColorPalette
.
.
Non, erreur :)
Cette façon génère un flux de donnée qu'il expose
dirctement au navigateur (context.Response.BinaryWrite
(image))
Il n'y a aucun fichier sur ton disque :)
Si tu te réfères à la compression :
"original.Save(ms, ici, eps)"
Le fichier compressé est sauvegardé dans "ms" qui est un
MemoryStream , un flux d'octet en mémoire et non pas un
fichire sur le disque.
C'est ce que j'utilise pour un de mes sites.
Toutes les images sont en base de données, et aucune sur
le disque, même quand on les affiche.
Aucune trace.
Sébastien-----Message d'origine-----
Merci
Cette façon de faire génère un fichier sur disque. Est-ce
possible dele faire sans générer de fichier sur disque ?
On Thu, 19 Aug 2004 09:21:23 -0700, "Sebastien Pertus"
wrote:Je l'avais oublié celle là :)
Tu auras aussi besoin de SaveJpgWithCompression
voilà les deux fonctions :
Private Shared Function GetTransparentColorPalette
(ByValoriginal As Bitmap) As ColorPalette
Dim testColor As Color
Dim newColor As Color
Dim pal As ColorPalette = original.Palette
Dim i As Integer
For i = 0 To (pal.Entries.Length - 1) - 1
testColor = pal.Entries(i)
If testColor.A = 0 Then
newColor = Color.FromArgb(0, testColor)
pal.Entries(i) = newColor
End If
Next i
Return pal
End Function
Private Overloads Shared Function
SaveJpgWithCompression(ByVal original As Image, ByVal compression As Long) As
MemoryStream
Dim ms As New MemoryStream
Dim eps As New EncoderParameters(1)
eps.Param(0) = New EncoderParameter(Encoder.Quality,
compression)
Dim ici As ImageCodecInfo = GetEncoderInfo
("image/jpeg")
original.Save(ms, ici, eps)
Return ms
End Function
Sébastien-----Message d'origine-----
Autre petite question
Ca me dit que GetTransparentColorPalette n'est pas
défini
On Thu, 19 Aug 2004 07:57:43 -0700, "Sebastien Pertus"
wrote:GetTransparentColorPalette
.
.
-----Message d'origine-----
Ca fonctionne presque
J'ai cependant encore d'autres messages d'erreur
Le nom ImageFormat n'est pas déclaré
Type colorPalette non défini
Type EncoderParameters non défini
Type ImageCodecInfo non défini
Merci
On Thu, 19 Aug 2004 10:17:24 -0700, Pertus Sébastien
wrote:Non, erreur :)
Cette façon génère un flux de donnée qu'il expose
dirctement au navigateur (context.Response.BinaryWrite
(image))
Il n'y a aucun fichier sur ton disque :)
Si tu te réfères à la compression :
"original.Save(ms, ici, eps)"
Le fichier compressé est sauvegardé dans "ms" qui est un
MemoryStream , un flux d'octet en mémoire et non pas un
fichire sur le disque.
C'est ce que j'utilise pour un de mes sites.
Toutes les images sont en base de données, et aucune sur
le disque, même quand on les affiche.
Aucune trace.
Sébastien-----Message d'origine-----
Merci
Cette façon de faire génère un fichier sur disque. Est-
possible dele faire sans générer de fichier sur disque ?
On Thu, 19 Aug 2004 09:21:23 -0700, "Sebastien Pertus"
wrote:Je l'avais oublié celle là :)
Tu auras aussi besoin de SaveJpgWithCompression
voilà les deux fonctions :
Private Shared Function GetTransparentColorPalette
(ByValoriginal As Bitmap) As ColorPalette
Dim testColor As Color
Dim newColor As Color
Dim pal As ColorPalette = original.Palette
Dim i As Integer
For i = 0 To (pal.Entries.Length - 1) - 1
testColor = pal.Entries(i)
If testColor.A = 0 Then
newColor = Color.FromArgb(0, testColor)
pal.Entries(i) = newColor
End If
Next i
Return pal
End Function
Private Overloads Shared Function
SaveJpgWithCompression(ByVal original As Image, ByVal compression As Long)
MemoryStream
Dim ms As New MemoryStream
Dim eps As New EncoderParameters(1)
eps.Param(0) = New EncoderParameter
compression)
Dim ici As ImageCodecInfo = GetEncoderInfo
("image/jpeg")
original.Save(ms, ici, eps)
Return ms
End Function
Sébastien-----Message d'origine-----
Autre petite question
Ca me dit que GetTransparentColorPalette n'est pas
défini
On Thu, 19 Aug 2004 07:57:43 -0700, "Sebastien Pertus"
wrote:GetTransparentColorPalette
.
.
.
-----Message d'origine-----
Ca fonctionne presque
J'ai cependant encore d'autres messages d'erreur
Le nom ImageFormat n'est pas déclaré
Type colorPalette non défini
Type EncoderParameters non défini
Type ImageCodecInfo non défini
Merci
On Thu, 19 Aug 2004 10:17:24 -0700, Pertus Sébastien
<anonymous@discussions.microsoft.com> wrote:
Non, erreur :)
Cette façon génère un flux de donnée qu'il expose
dirctement au navigateur (context.Response.BinaryWrite
(image))
Il n'y a aucun fichier sur ton disque :)
Si tu te réfères à la compression :
"original.Save(ms, ici, eps)"
Le fichier compressé est sauvegardé dans "ms" qui est un
MemoryStream , un flux d'octet en mémoire et non pas un
fichire sur le disque.
C'est ce que j'utilise pour un de mes sites.
Toutes les images sont en base de données, et aucune sur
le disque, même quand on les affiche.
Aucune trace.
Sébastien
-----Message d'origine-----
Merci
Cette façon de faire génère un fichier sur disque. Est-
possible de
le faire sans générer de fichier sur disque ?
On Thu, 19 Aug 2004 09:21:23 -0700, "Sebastien Pertus"
<Sebastien@8REMOVETHIS8Midiway.Fr> wrote:
Je l'avais oublié celle là :)
Tu auras aussi besoin de SaveJpgWithCompression
voilà les deux fonctions :
Private Shared Function GetTransparentColorPalette
(ByVal
original As Bitmap) As ColorPalette
Dim testColor As Color
Dim newColor As Color
Dim pal As ColorPalette = original.Palette
Dim i As Integer
For i = 0 To (pal.Entries.Length - 1) - 1
testColor = pal.Entries(i)
If testColor.A = 0 Then
newColor = Color.FromArgb(0, testColor)
pal.Entries(i) = newColor
End If
Next i
Return pal
End Function
Private Overloads Shared Function
SaveJpgWithCompression
(ByVal original As Image, ByVal compression As Long)
MemoryStream
Dim ms As New MemoryStream
Dim eps As New EncoderParameters(1)
eps.Param(0) = New EncoderParameter
compression)
Dim ici As ImageCodecInfo = GetEncoderInfo
("image/jpeg")
original.Save(ms, ici, eps)
Return ms
End Function
Sébastien
-----Message d'origine-----
Autre petite question
Ca me dit que GetTransparentColorPalette n'est pas
défini
On Thu, 19 Aug 2004 07:57:43 -0700, "Sebastien Pertus"
<sebastien@_REMOVETHIS_midiway.fr> wrote:
GetTransparentColorPalette
.
.
.
-----Message d'origine-----
Ca fonctionne presque
J'ai cependant encore d'autres messages d'erreur
Le nom ImageFormat n'est pas déclaré
Type colorPalette non défini
Type EncoderParameters non défini
Type ImageCodecInfo non défini
Merci
On Thu, 19 Aug 2004 10:17:24 -0700, Pertus Sébastien
wrote:Non, erreur :)
Cette façon génère un flux de donnée qu'il expose
dirctement au navigateur (context.Response.BinaryWrite
(image))
Il n'y a aucun fichier sur ton disque :)
Si tu te réfères à la compression :
"original.Save(ms, ici, eps)"
Le fichier compressé est sauvegardé dans "ms" qui est un
MemoryStream , un flux d'octet en mémoire et non pas un
fichire sur le disque.
C'est ce que j'utilise pour un de mes sites.
Toutes les images sont en base de données, et aucune sur
le disque, même quand on les affiche.
Aucune trace.
Sébastien-----Message d'origine-----
Merci
Cette façon de faire génère un fichier sur disque. Est-
possible dele faire sans générer de fichier sur disque ?
On Thu, 19 Aug 2004 09:21:23 -0700, "Sebastien Pertus"
wrote:Je l'avais oublié celle là :)
Tu auras aussi besoin de SaveJpgWithCompression
voilà les deux fonctions :
Private Shared Function GetTransparentColorPalette
(ByValoriginal As Bitmap) As ColorPalette
Dim testColor As Color
Dim newColor As Color
Dim pal As ColorPalette = original.Palette
Dim i As Integer
For i = 0 To (pal.Entries.Length - 1) - 1
testColor = pal.Entries(i)
If testColor.A = 0 Then
newColor = Color.FromArgb(0, testColor)
pal.Entries(i) = newColor
End If
Next i
Return pal
End Function
Private Overloads Shared Function
SaveJpgWithCompression(ByVal original As Image, ByVal compression As Long)
MemoryStream
Dim ms As New MemoryStream
Dim eps As New EncoderParameters(1)
eps.Param(0) = New EncoderParameter
compression)
Dim ici As ImageCodecInfo = GetEncoderInfo
("image/jpeg")
original.Save(ms, ici, eps)
Return ms
End Function
Sébastien-----Message d'origine-----
Autre petite question
Ca me dit que GetTransparentColorPalette n'est pas
défini
On Thu, 19 Aug 2004 07:57:43 -0700, "Sebastien Pertus"
wrote:GetTransparentColorPalette
.
.
.