Click to See Complete Forum and Search --> : How to draw a bitmap into a memory


Alexandra
December 5th, 1999, 05:05 AM
Hi!
Does anyone know how to draw a bitmap into a memory?
I am trying to use StdPicture.Render , but I can use only hdc object like picturebox, form , etc, unless I get run-time error "Invalid procedure call or argument (Error 5)".But I need draw the bitmap into a memory and after that I want to do sometning with it( for animation in ActiveX).

Thanks!


Dim hBmps(0 to 5) as Long

private Sub UserControl_ReadProperties(PropBag as PropertyBag)
Dim pic as IPictureDisp
Dim hCdc as Long
Dim hCdcTemp as Long
Dim hBmp as Long
Dim i as integer

...
namebmp = PropBag.ReadProperty("namebmp")
...

set pic = LoadPicture(namebmp)
hCdc = CreateCompatibleDC(UserControl.hdc)
hCdcTemp = CreateCompatibleDC(UserControl.hdc)
hBmp = CreateCompatibleBitmap(UserControl.hdc, bmp_width, bmp_height)
SelectObject hCdc, hBmp

pic.Render hCdc, 0, 0, bmp_width, bmp_height, 0, 0, bmp_width, bmp_height, 0

for i = 0 to 5
hBmps(i) = CreateCompatibleBitmap(UserControl.hdc, 8, 8)
SelectObject hCdcTemp, hBmps(i)
res = BitBlt(hCdcTemp, 0, 0, 8, 8, hCdc, i, 0, SRCCOPY)
hpen = CreatePen(0, 3, RGB(i * 10, 255, 0))

hbr = CreatePatternBrush(hBmps(i)) ' All for the CreatePatternBrush()

SelectObject UserControl.hdc, hbr
SelectObject UserControl.hdc, hpen
Rectangle hdc, 0, i * 50, 180, 50
next

End Sub

Ruth Glushkin
December 6th, 1999, 02:16 AM
Try to use Clipboard.SetData method to save your bitmap
and Clipboard.GetData to load it into your form.
There is a good example for GetData in VB Help.

Good Luck!

Alexandra
December 9th, 1999, 08:37 AM
Hi,Ruth!
Thanks for your try to replay!
Unfortunaly, the problem was in something other.
I have found the answer on the http://www.experts-exchange.com
Good luck!