|
-
Jun 16th, 2011, 12:18 PM
#1
Thread Starter
Lively Member
I´m lost!
Hi
I an trying to let my program save as jpg with a class from John Korejwa <[email protected]>.
I create a picture in my program and use :
BitBlt pbHidden.hDC, 0, 0, Picture5.Width / 15, Picture5.Height / 15, Picture5.hDC, 0, 0, SRCCOPY
For i = 1 To 200
DoEvents Next i
To copy all the contents labels and more to my new picturbox called pbHidden. This works well an I can use SavePicture to save as .bmp.
To save as jpg I have to get the contents of my Picturebox int this SubOpen
Code:
Private Sub mnuOpen_Click()
Dim MyPic As StdPicture
Dim FileName As String
FileName = FileDialog(Me, False, "Open Picture File", "Picture Files|*.jpg;*.jpeg;*.gif;*.bmp;*.wmp;*.rle;*.cur;*.ico;*.emf|All Files [*.*]|*.*")
If Len(FileName) > 0 Then
On Error Resume Next
Set MyPic = LoadPicture(FileName)
If Err.Number = 0 Then
Set m_Image = New cImage
m_Image.CopyStdPicture MyPic
If mnuAutosize.Checked Then SetFormSize m_Image
AdjustScrollBars m_Image
Me.Caption = App.Title & " - " & FileTitleOnly(FileName)
mnuSave(0).Enabled = True
Else
MsgBox "Can not load picture file" & vbCrLf & """" & FileName & """", vbExclamation, "File Load Error"
End If
Set MyPic = Nothing
End If
End Sub
I have tried to say Set MyPic = Form2.pbHidden.Picture
This only works if I (hardcode) a bitmap into my PictureBox then I get the file say a picture boy.gif. But if I use the results of
Code:
BitBlt pbHidden.hDC, 0, 0, Picture5.Width / 15, Picture5.Height / 15, Picture5.hDC, 0, 0, SRCCOPY
For i = 1 To 200
DoEvents
Next i
Then Set MyPic is empty and I get no picture to save.
Any help. Please excuse my English.
Keli
PS I will be away for the weekend so I will not comment until monday
Last edited by Hack; Jun 16th, 2011 at 12:27 PM.
Reason: Added Code Tags
-
Jun 17th, 2011, 02:02 AM
#2
-
Jun 17th, 2011, 03:54 AM
#3
Re: I´m lost!
Save as Jpg using GDIPlus:
Code:
Option Explicit
Public Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Public Type GdiplusStartupInput
GdiplusVersion As Long
DebugEventCallback As Long
SuppressBackgroundThread As Long
SuppressExternalCodecs As Long
End Type
Public Type EncoderParameter
GUID As GUID
NumberOfValues As Long
Type As Long
Value As Long
End Type
Public Type EncoderParameters
Count As Long
Parameter As EncoderParameter
End Type
Public Declare Function GdiplusStartup Lib "GDIPlus" ( _
token As Long, _
inputbuf As GdiplusStartupInput, _
Optional ByVal outputbuf As Long = 0) As Long
Public Declare Function GdiplusShutdown Lib "GDIPlus" ( _
ByVal token As Long) As Long
Public Declare Function GdipCreateBitmapFromHBITMAP Lib "GDIPlus" ( _
ByVal hbm As Long, _
ByVal hPal As Long, _
Bitmap As Long) As Long
'''''
'''''
Public Declare Function GdipDisposeImage Lib "GDIPlus" ( _
ByVal Image As Long) As Long
Public Declare Function GdipSaveImageToFile Lib "GDIPlus" ( _
ByVal Image As Long, _
ByVal filename As Long, _
clsidEncoder As GUID, _
encoderParams As Any) As Long
Public Declare Function CLSIDFromString Lib "ole32" ( _
ByVal str As Long, _
id As GUID) As Long
' ----==== SaveJPG ====----
Public Sub SaveJPG(ByVal pict As StdPicture, ByVal filename As String, Optional ByVal quality As Byte) '= 80
Dim tSI As GdiplusStartupInput
Dim lRes As Long
Dim lGDIP As Long
Dim lBitmap As Long
' Initialize GDI+
tSI.GdiplusVersion = 1
lRes = GdiplusStartup(lGDIP, tSI)
If lRes = 0 Then
' Create the GDI+ bitmap
' from the image handle
lRes = GdipCreateBitmapFromHBITMAP(pict.Handle, 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
' Initialize the encoder parameters
tParams.Count = 1
With tParams.Parameter ' Quality
' Set the Quality GUID
CLSIDFromString StrPtr("{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}"), .GUID
.NumberOfValues = 1
.Type = 4
.Value = VarPtr(quality)
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
If lRes Then
Err.Raise 5, , "Cannot save the image. GDI+ Error:" & lRes
End If
End Sub
-
Jun 17th, 2011, 04:48 AM
#4
-
Jun 20th, 2011, 11:32 AM
#5
Thread Starter
Lively Member
Re: I´m lost!
 Originally Posted by reexre
Save as Jpg using GDIPlus:
' ----==== SaveJPG ====----
Public Sub SaveJPG(ByVal pict As StdPicture, ByVal filename As String, Optional ByVal quality As Byte) '= 80
Dim tSI As GdiplusStartupInput
Dim lRes As Long
Dim lGDIP As Long
Dim lBitmap As Long
' Initialize GDI+
tSI.GdiplusVersion = 1
lRes = GdiplusStartup(lGDIP, tSI)
If lRes = 0 Then
' Create the GDI+ bitmap
' from the image handle
lRes = GdipCreateBitmapFromHBITMAP(pict.Handle, 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
' Initialize the encoder parameters
tParams.Count = 1
With tParams.Parameter ' Quality
' Set the Quality GUID
CLSIDFromString StrPtr("{1D5BE4B5-FA4A-452D-9CDD-5DB35105E7EB}"), .GUID
.NumberOfValues = 1
.Type = 4
.Value = VarPtr(quality)
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
If lRes Then
Err.Raise 5, , "Cannot save the image. GDI+ Error:" & lRes
End If
End Sub[/CODE]
Hi
I´m a little confused my picturebox is pbHidden.image where would I put that?
Keli
-
Jun 20th, 2011, 01:18 PM
#6
Re: I´m lost!
pbHidden.Refresh '(pbHidden.Autoredraw = true)
Call SaveJPG pbHidden.image , filename, Quality
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|