Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
How to change display settings: screen resolution, screen refresh rate
Custom GDI+ class
Capturing keyboard activity of another application with the Raw Input API (VFP9)
How to display Windows On-Screen Keyboard
How to print a bitmap file
Using the LoadImage function to have a bitmap file loaded and displayed on VFP main window
Winsock: sending email messages (SMTP, port 25)
System Image List Viewer
Using Video Capture: displaying on FoxPro form frames and previewing video obtained from a digital camera
Creating the Save dialog box to specify the drive, directory, and name of a file to save
Custom HttpRequest class (WinHTTP)
Printing Image File, programmatically set print page orientation to landscape
How to convert a bitmap file to monochrome format (1 bpp)
The window and its ancestors
Mapping and disconnecting network drives
How to download a file from the FTP server using FtpGetFile
Using EnumPrinters function to enumerate locally installed printers
Custom FTP Class for Visual FoxPro application
Displaying the associated icons and descriptions for files and folders
Displaying icons in the system tray (VFP9)
How to activate Windows Calculator
Drawing Windows predefined bitmaps using the LoadBitmap functions
Using FoxTray ActiveX control: System Tray Icon and menu attached to VFP form
Sending email messages with Simple MAPI
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: 32  
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 (50.16.132.180)
4 sec.Example: 'How to obtain Content-Type value for a file type from the System Registry'
12.55 min.Example: 'GetFocus returns a HWND value'
12.62 min.Example: 'Obtaining names and positions for shortcuts located on the Windows Desktop'
Language: 'C++'
33.25 min.Function: 'CeRapiFreeBuffer'
Function group: 'Remote Application Programming (RAPI)'
33.33 min.Example: 'How to create a desktop shortcut (shell link)'
1.13 hrs.Example: 'Winsock: retrieving Web pages using sockets (HTTP, port 80)'
 Example: 'Retrieving graphic capabilities of your display'
 Function: 'CloseEventLog'
Function group: 'Event Logging'
1.9 hrs.Example: 'Placing an arbitrary rectangular area of main VFP window on the Clipboard'
 Function: 'LookupAccountSid'
Google
Advertise here!