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

GdipSaveImageToFile 函数的图片质量无法控制

30 views
Skip to first unread message

white

unread,
Dec 3, 2009, 4:43:37 AM12/3/09
to
hi,
���� GdipSaveImageToFile ����ͼƬ�����JPEG��ʽ��Ȼ�������и�����
Quality���Ҵ�1���õ�100��ͼƬ������Զ���ܵ͡�

�����Ǵ��룺
Public Sub SaveJPG(ByVal pict As Long, ByVal filename As String, Optional
ByVal quality As Byte = 100)
Dim tSI As GdiplusStartupInput
Dim lRes As Long
Dim lGDIP As Long
Dim lBitmap As Long

Dim myQuality As Byte
myQuality = 100

' Initialize GDI+
tSI.GdiplusVersion = 1
lRes = GdiplusStartup(lGDIP, tSI)

If lRes = 0 Then

' Create the GDI+ bitmap
' from the image handle
lRes = GdipCreateBitmapFromHBITMAP(pict, 0, lBitmap)

If lRes = 0 Then
Dim tJpgEncoder As GUID
Dim tParams As EncoderParameters

' Initialize the encoder GUID
CLSIDFromString StrPtr("{557CF401-1A04-11D3-9A73-0000F81EF32E}"), _
tJpgEncoder

'CLSIDFromString StrPtr("{557CF401-1A04-11D3-9A73-0000F81EF32E}"),
_
' tJpgEncoder

' Initialize the encoder parameters
tParams.Count = 1
With tParams.Parameter ' Quality
' Set the Quality GUID
CLSIDFromString StrPtr("{1D5BE4B5-FA4A-452D-9CDD-5DB3505E7EB}"),
.GUID
.NumberOfValues = 1
.Type = 4
.Value = VarPtr(myQuality)
End With

' Save the image
lRes = GdipSaveImageToFile(lBitmap, StrPtr(filename), tJpgEncoder,
tParams)

' Destroy the bitmap
GdipDisposeImage lBitmap

End If

' Shutdown GDI+
GdiplusShutdown lGDIP

End If

End Sub

������һ�������ʹ����δ��롣Ȼ����һ��windows2003��������ʹ��������������Զ�������¼��̨������ʱ���ڡ���ʾ�������õ���ɫ����Ϊ256.
���Ұ������ɫ��������24λ��ʱ���������������JPEGͼƬ��������΢��Щ�����ǻ���Զ������ͼƬ�����������Ľ��

�ѵ����GDI�����WINDOWS����������йأ�

��λ�������æ�ɣ��챻����������ˡ�


һ����ˮ

unread,
Dec 4, 2009, 7:53:09 PM12/4/09
to

�ҵĴ����е㲻ͬ��
���ȣ���������һ��API�����һ���ֽ��ͱ�����

Private Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)

Dim aEncParams() As Byte


��End With���֮������2�䣺


ReDim aEncParams(1 To Len(tParams))
Call CopyMemory(aEncParams(1), tParams, Len(tParams))

�������������ģ�

GdipSaveImageToFile lBitmap, StrPtr(Filename), tJpgEncoder, aEncParams(1)

���ⷢ�����..GUID ����һ���㣬��֪����Ӱ�졣

white

unread,
Dec 15, 2009, 12:21:29 AM12/15/09
to
hi,
�dz���л���Ҳ���������һ�����ṩ��������䣬�����һ��ġ�
.GUIDû�ж�һ���㰡��

���ܷ����һ������������һ��JPGͼƬ��Ȼ��ԭ��С������������档�Ҳ��ԵĽ����һ��160K��ͼƬ��������ͳ��� 37k�ˣ�ͼƬ������󽵵͡�


"һ����ˮ" <wzc...@0733.com> д����Ϣ news:hfcasq$ope$1...@www.shinco.com...

0 new messages