Ik gebruik de onderstaande functie om een afbeelding die opgeslagen ligt in een byte array te resizen en te outputten op een pagina, dit werkt allemaal perfect, het enigste is dat deze de transparantie van een gif niet doorgeeft, waardoor de achtergrond van deze zwart word.
Ik heb al verschillende dingen geprobeerd, maar er schijnt niet echt een oplossing voor te zijn.
Ik heb al verschillende dingen geprobeerd, maar er schijnt niet echt een oplossing voor te zijn.
Visual Basic:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
| Public Function Get_Image(ByVal intMaxWidth As Short, _ ByVal intMaxHeight As Short, _ ByVal Image As Byte(), _ ByVal Response As HttpResponse, _ Optional ByVal Text As String = "") Dim x As Integer Dim ImageContent() As Byte = Image Dim strmImageStream As New IO.MemoryStream strmImageStream.Write(Image, 0, Image.Length) Dim bmpSource As System.Drawing.Bitmap = System.Drawing.Bitmap.FromStream(strmImageStream) Dim sizNewSize As New Size sizNewSize = NewthumbSize(bmpSource.Width, bmpSource.Height, intMaxWidth, intMaxHeight) Dim thisFormat = bmpSource.RawFormat Dim bmpOutput As Bitmap = New Bitmap(sizNewSize.Width, sizNewSize.Height) Dim g As Graphics = Graphics.FromImage(bmpOutput) g.Clear(Color.Transparent) g.DrawImage(bmpOutput, New Rectangle(0, 0, bmpOutput.Width, bmpOutput.Height)) g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic g.DrawImage(bmpSource, 0, 0, sizNewSize.Width, sizNewSize.Height) Dim encoderParams As System.Drawing.Imaging.EncoderParameters = New System.Drawing.Imaging.EncoderParameters Dim lngQuality As Long = 93 '0 = lowest, 100 = highest -- 95 seemed to be best ratio for file/quality' Dim encoderParam As Imaging.EncoderParameter = New Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, lngQuality) encoderParams.Param(0) = encoderParam Dim arrayICI As ImageCodecInfo() = ImageCodecInfo.GetImageEncoders() Dim jpegICI As ImageCodecInfo For x = 0 To arrayICI.Length - 1 If (arrayICI(x).FormatDescription.Equals("PNG")) Then jpegICI = arrayICI(x) Exit For End If Next Dim Memstream As New MemoryStream If Text <> "" Then 'voeg watermerk toe AddWaterMark(bmpOutput, Text, intMaxWidth) End If bmpOutput.Save(Memstream, ImageFormat.Png) Response.Clear() Response.ContentType = "image/png" Memstream.WriteTo(Response.OutputStream) Memstream.Flush() Memstream.Close() strmImageStream.Close() g.Dispose() bmpSource.Dispose() bmpOutput.Dispose() End Function |