Using Win32 functions in Visual FoxPro Image Gallery
GDI+ Image
..msdn
GdipDisposeImage
GdipGetImageFlags
GdipGetImageGraphicsContext
GdipGetImageHeight
GdipGetImageHorizontalResolution
GdipGetImagePalette
GdipGetImagePaletteSize
GdipGetImageRawFormat
GdipGetImageType
GdipGetImageVerticalResolution
GdipGetImageWidth
GdipGetPropertyCount
GdipGetPropertyIdList
GdipGetPropertyItem
GdipGetPropertyItemSize
GdipLoadImageFromFile
GdipRemovePropertyItem
GdipSaveImageToFile
GdipSetImagePalette
GdipSetPropertyItem
Code examples:
Displaying the color palette stored in an image file
Displaying the color palette stored in an image file

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
The code is based on custom GDI+ class. Download the class module first and save it in gdiplus.prg file.

Depending on its bit per pixel mode, an image file can store a color palette inside its data. GDI+ functions GdipGetImagePalette and GdipGetImagePaletteSize allow to retrieve the palette in a form of ColorPalette structure.
typedef struct {
        UINT Flags;
        UINT Count;
        ARGB Entries[1];
} ColorPalette;

The palettes below are retrieved from various image files:





 
SET PROCEDURE TO gdiplus ADDITIVE
 
* an instance of gdiplusinit must be created before
* and released after using any of gdi+ objects
PRIVATE gdiplus
gdiplus = CREATEOBJECT("gdiplusinit")
 
DO declare
 
LOCAL imgfile As gdiimage, nPaletteSize, cBuffer,;
    nResult, nEntryCount
 
imgfile = CREATEOBJECT("gdiimage", "c:\windows\FeatherTexture.bmp")
 
nPaletteSize=0
nResult = GdipGetImagePaletteSize(imgfile.himage, @nPaletteSize)
 
IF nResult <> 0
    = MESSAGEBOX("GdipGetImagePaletteSize call failed: " +;
        TRANSFORM(m.nResult))
    RETURN
ENDIF
 
cBuffer = REPLICATE(CHR(0), nPaletteSize)
nResult = GdipGetImagePalette(imgfile.himage, @cBuffer, nPaletteSize)
 
IF nResult <> 0
    = MESSAGEBOX("GdipGetImagePalette call failed: " +;
        TRANSFORM(m.nResult))
    RETURN
ENDIF
 
* number of entries in the palette
nEntryCount = buf2dword(SUBSTR(cBuffer,5,4))
IF nEntryCount = 0
    = MESSAGEBOX("The palette is empty.")
    RETURN
ENDIF
 
* creating a rectangle to draw the palette on
#DEFINE ENTRY_SIDE_PIXEL 16
#DEFINE BORDER_WIDTH_PIXEL 1
#DEFINE ENTRIES_PER_ROW 16
#DEFINE OFFSET_TO_ENTRIES 9
 
LOCAL oPalettePane As gdibitmap, nPaneWidth, nPaneRows, nPaneHeight,;
    nColIndex, nRowIndex, nEntryIndex, nArgb, nLeft, nTop
 
* calculate the size of a rectangle required to display the palette
nPaneWidth = BORDER_WIDTH_PIXEL +;
    (ENTRY_SIDE_PIXEL+BORDER_WIDTH_PIXEL) * ENTRIES_PER_ROW
 
nPaneRows = CEILING(nEntryCount/ENTRIES_PER_ROW)
 
nPaneHeight = BORDER_WIDTH_PIXEL +;
    (ENTRY_SIDE_PIXEL+BORDER_WIDTH_PIXEL) * m.nPaneRows
 
* create a bitmap to draw the palette on
oPalettePane = CREATEOBJECT("gdibitmap", nPaneWidth, nPaneHeight)
 
* fill the bitmap with white color
oPalettePane.graphics.FillRectangle(ARGB(255,255,255,255),;
    0, 0, nPaneWidth, nPaneHeight)
 
* drawing pallete entries on the bitmap
FOR nRowIndex=1 TO nPaneRows
    nTop = BORDER_WIDTH_PIXEL +;
        (ENTRY_SIDE_PIXEL+BORDER_WIDTH_PIXEL) * (nRowIndex-1)
 
    FOR nColIndex=1 TO ENTRIES_PER_ROW
        nEntryIndex = (nRowIndex-1) * ENTRIES_PER_ROW + nColIndex
 
        IF nEntryIndex <= nEntryCount
            nLeft = BORDER_WIDTH_PIXEL +;
                (ENTRY_SIDE_PIXEL+BORDER_WIDTH_PIXEL) * (nColIndex-1)
 
            nArgb = buf2dword(SUBSTR(cBuffer, OFFSET_TO_ENTRIES +;
                (nEntryIndex-1)*4, 4))
 
            oPalettePane.graphics.FillRectangle(nArgb, nLeft,nTop,;
                ENTRY_SIDE_PIXEL, ENTRY_SIDE_PIXEL)
        ENDIF
    NEXT
NEXT
 
* saving the rectangle to a file
oPalettePane.savetofile("palette.png")
* end of main
 
PROCEDURE declare
    DECLARE INTEGER GdipGetImagePalette IN gdiplus;
        INTEGER img, STRING @imgpalette, INTEGER palettesize
 
    DECLARE INTEGER GdipSetImagePalette IN gdiplus;
        INTEGER img, INTEGER imgpalette
 
    DECLARE INTEGER GdipGetImagePaletteSize IN gdiplus;
        INTEGER img, INTEGER @palettesize
 
 
 

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
2798 bytes  
Created: 2007-05-01 17:06:45  
Modified: 2007-05-03 17:32:35  
Visits in 7 days: 36  
Listed functions:
GdipGetImagePalette
GdipGetImagePaletteSize
GdipSetImagePalette
Printer friendly API declarations
My comment:
Palette entries obtained from an image files are drawn on a gdi+ bitmap object, which saves itself in a file
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
There are no notes on this subject.


Copyright © 2001-2013 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.1.55-log), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (107.22.25.119)
3 sec.Function: 'EnumPrinterData'
1.46 hrs.Function: 'CertFindCertificateInStore'
Function group: 'Cryptography Reference'
 Example: 'How to view icons stored in executable files (Icon Viewer)'
1.47 hrs.Function: 'GetObject'
1.75 hrs.Function: 'CreateWindow'
Function group: 'Window'
1.85 hrs.Function: 'DeleteVolumeMountPoint'
 Example: 'How to view icons stored in executable files (Icon Viewer) - II'
 Example: 'Enumerating connections made to a shared resource for the local computer (WinNT only)'
4.55 hrs.Example: 'Displaying animated images on FoxPro form with BitBlt and StretchBlt functions'
 Example: 'Using GetBinaryType (WinNT only) to determine the type of an executable file'
Google
Advertise here!