|
-
Jan 17th, 2008, 09:56 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Image to Buffer
Hello all, I'm making an application when once the image is changed from (picImage), which is a PictureBox; the Picture from picImage is saved into Buffered Memory (stdPicture in my choice) to be used as Checkpoints incase the user decides to relay back to another one.
Here is parts of my code so far:
Code:
Private History(255) As New StdPicture
Private CurrentHistoryNumber As Long 'what history point we are at.
Function MakeHistoryPoint(ByVal HistoryReason As String)
If CurrentHistoryNumber& < 255 Then
Set History(CurrentHistoryNumber&) = retrieveImage(picImage)
CurrentHistoryNumber& = CurrentHistoryNumber& + 1
lstHistory.AddItem HistoryReason$
End If
End Function
Private Function retrieveImage(ByVal SrcDC As PictureBox) As StdPicture
Dim tempPicture As New StdPicture
Call BitBlt(testOBJ.Handle, 0, 0, SrcDC.Width, SrcDC.Height, SrcDC.hDC, 0, 0, vbSrcCopy)
Set retrieveImage = tempPicture
End Function
My code works and all, but it when I try to retrieve the image from the History it does not show anything, this is the code I use to show the image into another picturebox (picSnapshot):
Code:
Call BitBlt(picSnapshot.hDC, 0, 0, History(lstHistory.ListIndex).Width, _
History(lstHistory.ListIndex).Height, History(lstHistory.ListIndex), 0, 0, vbSrcCopy)
I do notice that History(?) whatever's value is always at 0, meaning no picture was copied or something...does anyone have any clue what i'm doing wrong? Thanks,
RsT
*Please mark your original post as "Resolved" if you're question has been answered. You can do this by going into Thread Tools at the top of the Thread and "Mark Thread Resolved".
-
Jan 17th, 2008, 11:38 PM
#2
Re: Image to Buffer
In your Call BitBlt(picSnapshot.hDC.....
For the source you have History(lstHistory.ListIndex) , shouldn't that be,
History(lstHistory.ListIndex).hDC ?
-
Jan 18th, 2008, 12:04 AM
#3
Thread Starter
Addicted Member
Re: Image to Buffer
No i think it is directly handled like that..or by the .handle element which i have also tried (both run compiled correctly), but they do not show the image in the buffer..does anyone have any clue why?
*Please mark your original post as "Resolved" if you're question has been answered. You can do this by going into Thread Tools at the top of the Thread and "Mark Thread Resolved".
-
Jan 18th, 2008, 05:22 AM
#4
Re: Image to Buffer
You can't BitBlt to a StdPicture, BitBlt requires a Device Context as source and destination.
If you try...
Code:
Debug.print BitBlt(testOBJ.Handle, 0, 0, SrcDC.Width, SrcDC.Height, SrcDC.hDC, 0, 0, vbSrcCopy)
you will see that the return value is 0, which means fail.
Edit: try this
Code:
Option Explicit
Private History(255) As IPictureDisp
Private CurrentHistoryNumber As Long
Function MakeHistoryPoint(ByVal HistoryReason As String)
If CurrentHistoryNumber < 256 Then
Set History(CurrentHistoryNumber&) = picImage.Image
CurrentHistoryNumber = CurrentHistoryNumber + 1
lstHistory.AddItem HistoryReason
End If
End Function
Last edited by Milk; Jan 18th, 2008 at 06:01 AM.
Reason: corrected mistake in code that I noticed after reading Edgemeal's (removed) code. (which did not have that error)
-
Jan 18th, 2008, 05:48 AM
#5
Last edited by Edgemeal; Jan 18th, 2008 at 05:54 AM.
-
Jan 18th, 2008, 03:29 PM
#6
Thread Starter
Addicted Member
Re: Image to Buffer
Thanks Milk it works somewhat, ..when I load different images it shows it in picSnapshot, but once i draw on the Image in picImage it adds itself to history, but then once i lift up (at the point when u let go and stop drawing it saves another history point) it changes with all the previous pictures; each of history points have all the drawing I added (except when i loaded the image), why is it doing this? I followed your above example exactly
*Please mark your original post as "Resolved" if you're question has been answered. You can do this by going into Thread Tools at the top of the Thread and "Mark Thread Resolved".
-
Jan 18th, 2008, 06:33 PM
#7
Re: Image to Buffer
Oops, I was hasty when I posted it, change the
Code:
Private History(255) As IPictureDisp
to (what you had)
Code:
Private History(255) As New StdPicture
Then the last image saved will be independent of the last History point.
If your still having problems post more code.
One thing though, if say you image was a modest 256×256 pixels and your display Properties were set to 24bit, History() is potentially going to hog 48MB. At 512×512 it could hog 192MB. Are you aware of this? It would be a lot more complected but you would be possibly better off 'remembering' a rectangle covering the changed area, not the whole image.
-
Jan 18th, 2008, 07:36 PM
#8
Thread Starter
Addicted Member
Re: Image to Buffer
Yeah i'm aware that of it, they will be able to customize to how big they want it, and etc..., It's still not working though, the history picture is still the same. This is my code:
Code:
Private History(255) As New StdPicture
Private CurrentHistoryNumber As Long 'what history point we are at.
Private Sub picImage_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case PreviousIndexCommonTools&
Case 1 'Pen Tool
If Button = vbLeftButton Then
MakeHistoryPoint "iMage - Pen tool used"
ElseIf Button = vbRightButton Then
MakeHistoryPoint "iMage - Pen tool used"
End If
End Select
End Sub
Private Sub doPicStuff()
If FileExists(lstAlbumPath.List(lstAlbum.ListIndex)) = True Then
fraImg.Visible = True
picImage.Picture = LoadPicture(lstAlbumPath.List(lstAlbum.ListIndex))
MakeHistoryPoint "iMage loaded (" & lstAlbum.List(lstAlbum.ListIndex) & ")"
End If
Function MakeHistoryPoint(ByVal HistoryReason As String)
If CurrentHistoryNumber < 256 Then
Set History(CurrentHistoryNumber&) = picImage.Image
CurrentHistoryNumber = CurrentHistoryNumber + 1
lstHistory.AddItem HistoryReason
End If
End Function
End Sub
Private Sub lstHistory_Click() 'show image
picSnapshot.Picture = History(lstHistory.ListIndex)
End Sub
*Please mark your original post as "Resolved" if you're question has been answered. You can do this by going into Thread Tools at the top of the Thread and "Mark Thread Resolved".
-
Jan 18th, 2008, 07:47 PM
#9
Re: Image to Buffer
try
Code:
Private Sub lstHistory_Click() 'show image
set picSnapshot.Picture = History(lstHistory.ListIndex)
End Sub
I'm really rusty with VB's native graphics methods
-
Jan 18th, 2008, 09:00 PM
#10
Re: Image to Buffer
 Originally Posted by XRsTX
Yeah i'm aware that of it, they will be able to customize to how big they want it, and etc..., It's still not working though, the history picture is still the same.
Ya that is strange, I can't seem to see why picImage doesn't change to the selected history, but if I do this then it works!
Code:
Private Sub MakeHistoryPoint(ByVal HistoryReason As String)
Set History(CurrentHistoryNumber) = picImage.Image
lstHistory.AddItem HistoryReason
lstHistory.Selected(CurrentHistoryNumber) = True
CurrentHistoryNumber = CurrentHistoryNumber + 1
End Sub
Code:
Private Sub lstHistory_Click()
Set History(255) = picImage.Image ' just tp preserve current image
Set picImage.Picture = History(lstHistory.ListIndex)
Set picSnapshot.Picture = History(lstHistory.ListIndex)
Set picImage.Picture = History(255) ' restore preserved image
End Sub
-
Jan 18th, 2008, 09:46 PM
#11
Thread Starter
Addicted Member
Re: Image to Buffer
Yeah I don't know either, I thought that what Milk had was correct cause I remember doing something like that before (i'm kinda rusty, haven't VB'd in awhile), but for some reason yeah Edgemeal that works perfectly...except I modify it a bit, but thanks for all the help.
*Please mark your original post as "Resolved" if you're question has been answered. You can do this by going into Thread Tools at the top of the Thread and "Mark Thread Resolved".
-
Jan 18th, 2008, 09:50 PM
#12
Re: Image to Buffer
 Originally Posted by XRsTX
except I modify it a bit, but thanks for all the help.
What did you modify, I'm curious now!
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
|