Using Win32 functions in Visual FoxPro Image Gallery
Code examples:
Custom FTP Class for Visual FoxPro application
Printing Image File, programmatically set print page orientation to landscape
Splash Screen for the VFP application
Attaching menu to a top-level form
Drawing icons associated with the VFP main window
Testing serial ports
Reading the structure of VFP main menu
Accessing Adobe Reader 7.0 main menu from VFP application
Custom HttpRequest class (WinHTTP)
GDI+: sending image of FoxPro form to printer
Using shared memory to exchange data between applications (processes)
Browsing Windows Known Folders (Special Folders)
Disconnecting USB Mass Storage Device programmatically
How to prevent users from accessing the Windows Desktop and from switching to other applications
How to make a VFP form fading out when released (GDI+ version)
Copying picture of the active form to the Clipboard using Enhanced Metafile API functions
How to change display settings: screen resolution, screen refresh rate
Enumerating devices installed on the local machine
System Image List Viewer
Detecting changes in connections to removable drives (VFP9)
Creating a clipping region from the path selected into the device context of a form
How to make a VFP form fading out when released (GDI version)
Switching between keyboard layouts
Creating irregularly shaped FoxPro form using transparency color key
How to convert a bitmap file to monochrome format (1 bpp)

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
Versions:
click to open
Before you begin:
It all started with a question a developer posted in the Universal Thread Visual FoxPro forum:
Does anyone know how to create a monochrome bitmap or monochrome tiff file from a VFP report?
...
I need to automate the process. We are using this for a faxing application and it must work in a multi-user environment
Well, there is ReportListener object in VFP9 that can solve at least a part of this task. Its OutputPage method can render the output of a report to a bitmap file. The code is very simple (requires VFP9):

LOCAL oListener As ReportListener, nPageIndex
oListener = CREATEOBJECT("ReportListener")
oListener.ListenerType=3 && renders all pages at once

* make sure the report can load and run
REPORT FORM MyReport PREVIEW OBJECT oListener

FOR nPageIndex=1 TO oListener.PageTotal
        cOutputFile = "tmp"+TRANS(nPageIndex)+".bmp"
        oListener.OutputPage(nPageIndex,;
                cOutputFile, 105, 0,0,768,1024) && 105=bitmap
NEXT

I run the code and voila! It created one bitmap file for each page of my report. But the output files were nothing but small: 32 bits per pixel, 3.28 MB each. Still I was half way through.

Then I spent some time in Visual FoxPro trying in vain to convert bitmaps to monochromes using GDI+ API along with several GDI calls like CreateCompatibleBitmap, BitBlt and so on. The GdipGetImageGraphicsContext absolutely refused to accept monochrome HBITMAP handles.

After that I tried to find a solution using C# .NET, any solution at all. The Bitmap object did not help either. It failed to Clone to the PixelFormat.Format1bppIndexed, each time producing the System.OutOfMemoryException. That appeared consistent with GpStatus=3 returned by the GdipGetImageGraphicsContext function in my VFP tests.

Finally I gave up on GDI+ and switched to good old GDI API calls. And they worked perfectly, credits to the LoadImage for doing the actual conversion.
 
  Members area. Log in to view this example.
 
  User name:
  Password:
 
 
  Forgot your password?
 
  Sign up for
the Membership
 
 


User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
5268 bytes  
Created: 2005-09-08 15:31:56  
Modified: 2010-01-14 12:01:18  
Visits in 7 days: 121  
Listed functions:
CloseHandle
CreateCompatibleDC
CreateFile
DeleteDC
DeleteObject
GetDIBits
GetObject
GlobalAlloc
GlobalFree
LoadImage
SelectObject
WriteFile
ZeroMemory
Printer friendly API declarations
My comment:
The code above implements:

PROCEDURE SaveBitmapAsMonochrome(srcfile As String, dstfile As String)

To create HBITMAP from a bitmap file I use the LoadImage with LR_LOADFROMFILE and LR_MONOCHROME flags. This way, it takes care of all color-to-monochrome mumbo-jumbos, which fact I am very happy with.

The source HBITMAP is selected into a memory device context. Then both of them are passed to the SaveBitmapToFile procedure.

The procedure is a bit hard-coded, which means it produces monochrome bitmap files only. It creates BITMAPINFOHEADER and BITMAPFILEHEADER structures, extracts bitmap binary data using the GetDIBits function and then saves everything to a file.

* * *
The writing and reading from temporary file makes the C# code noticeably slow on large files, which appears to be an unavoidable pay-off for the utter simplicity of this approach.
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:
A.M. | 2007-10-31 11:05:13
Bit2Mono.exe Changes Color Bitmaps to Monochrome
http://support.microsoft.com/kb/q77282/

Copyright 2001-2017 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.6.38), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (54.198.134.32)
13 sec.Function: 'GetTextColor'
Function group: 'Font and Text'
25 sec.Function: 'CeCreateDirectory'
Function group: 'Remote Application Programming (RAPI)'
36 sec.Function: 'SQLBrowseConnect'
Function group: 'ODBC API'
48 sec.Function: 'DrawDibOpen'
Function group: 'Windows Multimedia'
58 sec.Function: 'GetTextFace'
Function group: 'Font and Text'
1.15 min.Function: 'ntohs'
Function group: 'Windows Sockets 2 (Winsock)'
1.35 min.Function: 'FtpRenameFile'
Function group: 'Internet Functions (WinInet)'
1.53 min.Gallery
1.7 min.Function: 'GetPrinterData'
Function group: 'Printing and Print Spooler'
1.9 min.
Function group: 'Multiple Display Monitors'
Google
Advertise here!