vb.net - Saving Bitmaps In a list always return the same image -


im creating ctrl + z undo feature image editor, each click on screen save image code:

private sub savemap(byval sender object, byval e eventargs) handles picturebox1.click     dim asd new bitmap(form6.picturebox1.image)     globalvariables.backup.add(form6.picturebox1.image)     asd.dispose() end sub 

and everytime user press ctrl + z code executed

private sub picturebox1_keypress(byval sender object, byval e keyeventargs) handles me.keydown     if e.keycode = keys.z , e.control         globalvariables.backup.removeat(globalvariables.backup.count - 1)         form6.picturebox1.image = new bitmap(globalvariables.backup.last)         form6.picturebox1.refresh()     end if end sub 

but seens bitmaps im saving in public shared backup new list(of bitmap) same.

because no matter index return globalvariables.backup.item() , every of them return exact same image.

why bitmaps on list getting replaced, , not added 1 after another?

you not saving new bitmap, reference picturebox.image. reference, change when picturebox.image changes. should save new image list cloning displayed:

private sub savemap(byval sender ...     dim bmp bitmap     bmp = form6.picturebox1.image.clone   ' clone image      globalvariables.backup.add(bmp)       ' save copy      ' dispose of later when remove list end sub 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -