Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

24 Bit Tiff to 1 Bit Tiff using GDI+

56 views
Skip to first unread message

Zach Becker

unread,
Aug 6, 2003, 2:49:52 PM8/6/03
to
I am writing a scanning/imaging application using VB 6.0 in which I am
using GDI+ to load and save .TIF files in/out pictureboxes. My main
problem is that the .TIF files saved are in True Color (24-bit) format
and I am looking for either Monochrome (1-bit) or Grayscale (8-bit)
format as the output. Does anyone have any information on GDI+ or the
problem I am having?

Thanks so much!

Here is an example of the code...

' saves the contents of a picturebox to a file
' supports GIF/JPG/TIF/PNG and various others
Public Function PictureBoxToFile(ByVal pic As PictureBox, ByRef
sFilename As String, Optional lQuality As Long = 85) As Long
Dim sExtension As String
Dim bitmap As Long
Dim lError As Long
Dim params As EncoderParameters
Dim lQual As Long
Dim lIndex As Long
Dim tguid As GDIPlus.Guid
sExtension = GetExtension(sFilename)
lIndex = ExtensionExists("*." & sExtension)
If lIndex > -1 Then
lError = GdipCreateBitmapFromHBITMAP(pic.Picture.Handle,
pic.Picture.hPal, bitmap)
If Not lError Then
If (Asc(sExtension) And Not 32) = vbKeyJ Then ' lazy
JPEG/JPG/JPE/JFIF checking :P
lQual = lQuality
params.Count = 1
params.Parameter.Guid = StringToGuid(EncoderQuality)
params.Parameter.NumberOfValues = 1
params.Parameter.Type = EncoderParameterValueTypeLong
params.Parameter.Value = VarPtr(lQual)
lError = GdipSaveImageToFile(bitmap, sFilename,
tGuids(lIndex), params)
Else
lError = GdipSaveImageToFile(bitmap, sFilename,
tGuids(lIndex), ByVal 0)
End If
If Not lError Then
GdipDisposeImage bitmap
PictureBoxToFile = True ' tada!
Else
RaiseEvent Error(lError, GdiErrorString(lError))
End If
Else
RaiseEvent Error(lError, GdiErrorString(lError))
End If
End If
End Function

Mike D Sutton

unread,
Aug 7, 2003, 11:39:56 PM8/7/03
to
> I am writing a scanning/imaging application using VB 6.0 in which I am
> using GDI+ to load and save .TIF files in/out pictureboxes. My main
> problem is that the .TIF files saved are in True Color (24-bit) format
> and I am looking for either Monochrome (1-bit) or Grayscale (8-bit)
> format as the output. Does anyone have any information on GDI+ or the
> problem I am having?
<code snipped>

See if these pages are of any use to you, there may be more if you hunt
around on Google:
http://www.dotnet247.com/247reference/msgs/29/147843.aspx
http://csharpfriends.com/Forums/ShowPost.aspx?PostID=6329#6329
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: ED...@mvps.org
WWW: Http://www.mvps.org/EDais/


0 new messages