iNET Interactive - Online Advertising Agency
          
Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Knowledge Base > Code Library > Color Quantization and GDI+ GIF with much better quality


Reply
 
Thread Tools Display Modes
  #1  
Old 07-21-2003, 02:02 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Preferred language:
Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,239
Default Color Quantization and GDI+ GIF with much better quality

This sample contains a very basic GDI+ class wrapper. It is similar in some ways to the .net GDI+ wrapper.

It shows how to decrease colors in an image from 24bit to 8 bit. And various other numbers of colors as well, from 8 to 256. Quantization is done by using an octree. Many thanks to vbaccelerator.com.

GDI+ uses a halftone palette by default to save the image to file. This leads to terrible quality in many cases. This sample greatly improves the saved GIF image. Enjoy!
Attached Files
File Type: zip gdiplus3.zip (22.9 KB, 1254 views)
Reply With Quote
  #2  
Old 07-21-2003, 02:12 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Preferred language:
Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,239
Default

A quick note for VB5 users. In frmViewer.frm you can make a slight change. I fixed the .vbp, but forgot the form.

Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "COMCTL32.OCX"

That should be the correct version.
Reply With Quote
  #3  
Old 07-22-2003, 12:58 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Preferred language:
Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,239
Default

I found a small bug in the code. The last scan line of the image is not shown. I had been changing the loop around and left out an equals sign. In modQuant.bas the QuantizeImage function change the loop to:

Loop While Y >= -1
Reply With Quote
  #4  
Old 02-11-2005, 11:49 AM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Preferred language:
Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,239
Default GDI+ 1.1 Quantization

The gdiplus.dll version 6.x now offers color quantization with minimal coding. With as little as two lines of code a GDI+ bitmap can be quantized with an optimal palette. If a custom palette is desired, GDI+ does excellent error reduction dithering from the original image to the new palette. This example also demonstrates histogram generation for an image.

If you have Office 03, Visio 03 or PowerPoint Viewer 03, then you should have version 6 installed already. You will need to move the dll to the app.path of this project, or \windows\system32 or equivalent. If you are an XP user, place the gdiplus.dll in the app.path of the exe. Then create an empty file called: Exename.exe.local

That will allow XP Side-by-side component sharing to find the dll.

The new tlb has a new GUID and version, so it will not interfere with any previous versions. It cannot be used with the 5.0 version of the dll, as various functions do not exist.

If you do not have any of those installed, you can get the free PowerPoint Viewer 03 here: http://www.microsoft.com/downloads/d...displaylang=en

Once installed, you will then find the gdiplus.dll 6.0.32.64 (or newer) installed at: c:\program files\microsoft office\powerpoint viewer. Copy the file and place as mentioned previously.
Attached Files
File Type: zip quantize_1_1.zip (93.0 KB, 527 views)
__________________
Quis custodiet ipsos custodues.

Last edited by OnErr0r; 06-12-2005 at 07:15 PM.
Reply With Quote
  #5  
Old 12-21-2005, 11:49 AM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Preferred language:
Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,239
Default

GDI+ 1.1 users on XP, see this important note.
__________________
Quis custodiet ipsos custodues.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Advertisement: