Page 1 of 1

Simple Bitblt_

Posted: Wed May 11, 2005 7:05 pm
by Garfield9992003
Why are the 2 jpg´s from the code different?
They should be identical.
Its only a sample code from my project.

Code: Select all

  hBMP.l=CreateImage(0, 200, 400) 
  dcv.l=StartDrawing(ImageOutput()) 
  Box(50,50,100,300,RGB(255,255,255)) 
  StopDrawing() 
  
  MemDC.l = CreateCompatibleDC_(dcv) 
  BitmapID.l = CreateImage(1,200,400) 
  SelectObject_(MemDC, BitmapID) 
  BitBlt_(MemDC, 0, 0, 200, 400, dcv , 0, 0, #SRCCOPY) 
  DeleteDC_(MemDC) 
  
  UseJPEGImageEncoder() 
  SaveImage(0, "0.jpg",#PB_ImagePlugin_JPEG) 
  SaveImage(1, "1.jpg",#PB_ImagePlugin_JPEG)
Regards

Frank

Posted: Wed May 11, 2005 8:36 pm
by srod
Hiya,

you just need to reorder the statements a little as the original

Code: Select all

BitmapID.l = CreateImage(1,200,400) 
line was destroying the original device context. Also had to move the StopDrawing() command.

Code: Select all

BitmapID.l = CreateImage(1,200,400) 
hBMP.l=CreateImage(0, 200, 400) 
dcv.l=StartDrawing(ImageOutput()) 
Box(50,50,100,300,RGB(255,255,255)) 

MemDC.l = CreateCompatibleDC_(dcv) 
SelectObject_(MemDC, BitmapID) 
BitBlt_(MemDC, 0, 0, 200, 400, dcv , 0, 0, #SRCCOPY) 
DeleteDC_(MemDC) 
StopDrawing() 
 
UseJPEGImageEncoder() 
SaveImage(0, "0.jpg",#PB_ImagePlugin_JPEG) 
SaveImage(1, "1.jpg",#PB_ImagePlugin_JPEG)
Regards.

Posted: Wed May 11, 2005 10:19 pm
by Garfield9992003
Thanx a lot, it works fine!

But now, i´ve my second problem with image-handles :(

I want to copy 2 images into a new one:

Images 0 and 1 are given. How can i retrieve a handle on it?
Image 2 keeps black :(

What´s wrong?

Code: Select all

  id1=UseImage(0) ;image 200x200 pixel stored in image #1
  id2=UseImage(1) ;image 200x200 pixel stored in image #2
  img=CreateImage(2, 200, 200)
  handle=StartDrawing(ImageOutput()) 
  mem = CreateCompatibleDC_(handle)   
  SelectObject_(mem, img)
  BitBlt_(mem, 0,0, 200,200, id2, 0,0, #SRCCOPY)
  BitBlt_(mem, 30,30, 140,140, id1, 30,30, #SRCCOPY)
  DeleteDC_(mem)
  StopDrawing()
Regards

Frank

Posted: Wed May 11, 2005 10:45 pm
by srod
UseImage() does not return a device context as required by BitBlt. It actually returns a handle to the underlying bitmap itself.

I'll have a little tinker.

Posted: Wed May 11, 2005 10:54 pm
by Garfield9992003
Damn, i thought it :(

And how could i receive a dc from an image?

I had no results with GetDC.

Is there another way?


Thx.

Frank

Posted: Wed May 11, 2005 11:56 pm
by srod
The following seems to work okay, though there is probably a better way of doing this.

The problem with StartDrawing() StopDrawing() is that the hdc's are released automatically before we have time to pass them to the BitBlt function.

Try this.

Code: Select all

img0=UseImage(0) 
img1=UseImage(1) 
CreateImage(2, 200, 200) 
hdc2=StartDrawing(ImageOutput()) 
hdc0 = CreateCompatibleDC_(hdc2)    
hdc1 = CreateCompatibleDC_(hdc2)    

SelectObject_(hdc0, img0) 
SelectObject_(hdc1, img1)

BitBlt_(hdc2, 0,0, 200,200, hdc0, 0,0, #SRCCOPY) 
BitBlt_(hdc2, 30,30, 140,140, hdc1, 0,0, #SRCCOPY) 
StopDrawing()

DeleteDC_(hdc0) 
DeleteDC_(hdc1) 
I tested it with the following:

Code: Select all

img0=CreateImage(0, 200, 200) 
img1=CreateImage(1, 200, 200) 

UseImage(0) ;image 200x200 pixel stored in image #1 
id=StartDrawing(ImageOutput()) 
Box(0,0,200,200,RGB(255,255,255)) ; White box.
StopDrawing()
UseImage(1) ;image 200x200 pixel stored in image #2 
StartDrawing(ImageOutput()) 
Box(0,0,200,200,RGB(255,255,0)) ; Yellow box.
StopDrawing()


img0=UseImage(0) 
img1=UseImage(1) 
CreateImage(2, 200, 200) 
hdc2=StartDrawing(ImageOutput()) 
hdc0 = CreateCompatibleDC_(hdc2)    
hdc1 = CreateCompatibleDC_(hdc2)    

SelectObject_(hdc0, img0) 
SelectObject_(hdc1, img1)

BitBlt_(hdc2, 0,0, 200,200, hdc0, 0,0, #SRCCOPY) 
BitBlt_(hdc2, 30,30, 140,140, hdc1, 0,0, #SRCCOPY) 
StopDrawing()

DeleteDC_(hdc0) 
DeleteDC_(hdc1) 

UseJPEGImageEncoder() 
SaveImage(0, "0.jpg",#PB_ImagePlugin_JPEG) 
SaveImage(1, "1.jpg",#PB_ImagePlugin_JPEG)
SaveImage(2, "2.jpg",#PB_ImagePlugin_JPEG)

Posted: Thu May 12, 2005 1:04 am
by Garfield9992003
Wow, it work great!

Thanks you a lot!


Frank