TrueColorToPalette v 1.1
High-quality Jpeg to GIF conversion in .NET
With this product you can convert a True Color image to
palettized one using Floyd-Steinberg dithering algorithm. GDI+, by default,
uses a halftone palette, that creates ugly looking, poor quality images.
New algorithm gives images without grain looking just like original ones. This
is especially useful for photography. In order to use the new conversion
technique, you just need to copy one file. This is useful for hosting
servers because you don't need to register any components.
Download TrueColorToPalette.zip
ASP.NET Sample that creates GIF image and ouputs it to stream can be found
here.
The screenshot of a sample VB.NET program.
 |
 |
| The image in memory |
Conversion from jpeg to gif |
This VB.NET program let you change the number of colors, transparency and
dithering options. The complete source code can be found in the distribution
file.
|
no transparent
dither |
no transparent
no dither |
transparent
dither |
transparent
no dither |
| 256 colors |
 |
 |
 |
 |
| 128 colors |
 |
 |
 |
 |
| 16 colors |
 |
 |
 |
 |
| 8 colors |
 |
 |
 |
 |
| 3 colors |
 |
 |
 |
 |
| 2 colors |
 |
 |
 |
 |
Source code:
Class ConvertToPalette
Public Class ConvertToPalette
<DllImport("TrueColorToPalette.dll", CharSet:=CharSet.Auto)> _
Public Overloads Shared Function ConvertToPalette(ByRef img As IntPtr, _
ByRef img2 As IntPtr, _
ByRef pal As IntPtr, _
ByVal dwWidth As Int32, _
ByVal dwHeight As Int32, _
ByVal dwStride As Int32, _
ByVal dwStride2 As Int32, _
ByVal dwDither As Int32, _
ByVal dwColors As Int32) _
As Int32
End Function
Public Function ConvertToPal(ByVal bitmap As Bitmap, _
ByVal dither As Int32, _
ByVal dwColors As Int32) _
As Bitmap
Dim bitmapPalette As Bitmap
Dim rect As Rectangle
Dim index As Int32
Dim palette As ColorPalette
Dim bitmapData As BitmapData
Dim format As Imaging.PixelFormat
Dim tempPalette As IntPtr
Dim bitmapPaletteData As BitmapData
Dim formatPalette As Imaging.PixelFormat
Dim paletteByte(256 * 4) As Byte
Dim width As Int32
Dim height As Int32
width = bitmap.Width
height = bitmap.Height
rect.X = 0
rect.Y = 0
rect.Width = width
rect.Height = height
bitmapPalette = New Bitmap(width, height, PixelFormat.Format8bppIndexed)
palette = bitmapPalette.Palette
format = bitmap.PixelFormat
formatPalette = bitmapPalette.PixelFormat
tempPalette = Marshal.AllocCoTaskMem(256 * 4)
bitmapData = bitmap.LockBits(rect, _
ImageLockMode.ReadWrite, _
format)
bitmapPaletteData = bitmapPalette.LockBits(rect, _
ImageLockMode.ReadWrite, _
formatPalette)
ConvertToPalette(bitmapData.Scan0, _
bitmapPaletteData.Scan0, _
tempPalette, _
width, _
height, _
bitmapData.Stride, _
bitmapPaletteData.Stride, _
dither, _
dwColors)
Marshal.Copy(tempPalette, paletteByte, 0, 256 * 4)
bitmap.UnlockBits(bitmapData)
bitmapPalette.UnlockBits(bitmapPaletteData)
For index = 0 To palette.Entries.Length - 1
palette.Entries(index) = Color.FromArgb(255, _
paletteByte(index * 4), _
paletteByte(index * 4 + 1), _
paletteByte(index * 4 + 2))
Next
bitmapPalette.Palette = palette
Marshal.FreeCoTaskMem(tempPalette)
ConvertToPal = bitmapPalette
End Function
End Class
Features:
-
Royalty-free for software and web site developers
-
The easy installation. No need to register the component, just copy the file to
bin directory
-
Converts from True Color to palettized images
-
Creates transparent GIF image
-
Based on ASP Painter technology
Quick start instruction:
-
Copy TrueColorToPalette.dll file into bin directory of VB.NET project
-
Add class ConvertToPalette to project
-
Add namespace System.Drawing.Drawing2D,
System.Drawing, System.Drawing.Imaging, System.Runtime.InteropServices
-
Create new instance of ConvertToPalette class
-
Make new palette bitmap with ConvertToPal method
-
Save bitmap to a file or stream.
Short sample
Imports System.Drawing.Drawing2D
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
Public dwColors As Int32
Public dwDither As Int32
Public bmpPalette As Bitmap
Public bmpTrueColor As Bitmap
.... skip .....
Protected Overrides Sub OnPaint(ByVal e As _
System.Windows.Forms.PaintEventArgs)
Dim Conv As ConvertToPalette = New ConvertToPalette()
bmpPalette = Conv.ConvertToPal(bmpTrueColor, dwDither, dwColors)
e.Graphics.DrawImage(bmpPalette, 0, 0)
End Sub
.... skip .....
TrueColorToPalette purchase
TrueColorToPalette Trial -
Download now!
|
|
Distribution package includes |
|
- TrueColorToPalette.dll file
|
|
- ASP.NET and VB.NET samples |
License Summary: Can be used freely for non-commercial purpose.
Limitation: no more than 16 colors in resulting image.
TrueColorToPalette Basic
- Purchase Now!
|
|
Distribution package includes |
|
- TrueColorToPalette.dll file
|
|
- ASP.NET and VB.NET samples |
|
- one site/workstation license |
License Summary: TrueColorToPalette Basic can be used for any purpose
including the development of derivative products
TrueColorToPalette PRO -
Purchase Now!
|
|
Distribution package includes |
|
- TrueColorToPalette.dll file
|
|
- ASP.NET and VB.NET samples |
|
- five sites/workstations license |
License Summary: TrueColorToPalette Pro can be used for any purpose
including the development of derivative products
TrueColorToPalette Enterprise -
Purchase Now!
|
|
Distribution package includes |
|
- TrueColorToPalette.dll file
|
|
- ASP.NET and VB.NET samples |
|
- unlimited number of sites/workstations license |
License Summary: TrueColorToPalette Enterprise version can be used freely
for any purpose
To order by phone, call (877)-REGSOFT and tell the product ID
Technical support: support@asppainter.com