pixmap trouble...
BlitzMax Forums/BlitzMax Beginners Area/pixmap trouble...
| ||
Ok ok I read all the threads present in the forum about pixmap, something is clear now, but I have a problem with this'test copy image Graphics 640,480 Global load_image:TPixmap=LoadPixmap("gfx/world_2.png") If load_image.format<>PF_RGBA8888 Then load_image=ConvertPixmap( load_image,PF_RGBA8888 ) Copy(load_image) Flip WaitKey End Function Copy(pix:TPixmap) Local pix_dest:TPixmap=CreatePixmap(pix.width,pix.height,PF_RGBA8888) Local psource:Byte Ptr Local pdest:Byte Ptr psize=32*4*pix.height For k=0 To pix.width-32 Step 32 psource=PixmapPixelPtr(pix,k,0) 'pdest=PixmapPixelPtr(pix_Dest,pix.width-k,0) pdest=PixmapPixelPtr(pix_Dest,k,0) MemCopy(pdest,psource,psize) Next 'only for test image=ConvertToImage(pix_dest) DrawImage image,0,0 End Function Function ConvertToImage:timage(pix:TPixmap) Local size_x:Int=pix.width Local size_y:Int=Pix.height Local pdest:Byte Ptr Local psource:Byte Ptr psource=PixmapPixelPtr(pix,0,0) Local psize:Int=size_x*size_y*4 '4 bytes per pixel assuming RGBA8888 format pixmap temp_image:TImage=CreateImage(size_x,size_y,1,iflags|DYNAMICIMAGE) 'create dummy image in case we want to do realtime conversion between pixmaps and images/textures temp_pixmap:TPixmap=LockImage(temp_image,0,False,True) 'Lock our dummy image so we can draw to it pdest=PixmapPixelPtr(temp_pixmap,0,0) 'Set our destination pointer to the image's pixmap MemCopy(pdest,psource,psize) 'Copy the pixels from the pixmap in memory to the image/texture's pixmap UnlockImage(temp_image) 'Let the image be rendered now Return temp_image End Function The goal is copy from a pixmap to another one... Why I get only a black image? |
| ||
If you want to copy a pixmap then why not use copypixmap? mypix2:TPixmap=copypixmap(mypix1) If you want to load a pixmap into an image then image:TImage=loadimage(mypix) |
| ||
I need to 'dismantle' an image into another image (or pixmap) copying only a small piece/slice of the original in different position. I already know Copy & Paste method of pixmap but why my example doesn't work? |
| ||
I do something similar here Might be because psize isn't big enough? This seems to work... Graphics 640,480 Global load_image:TPixmap=LoadPixmap("max.png") If load_image.format<>PF_RGBA8888 Then load_image=ConvertPixmap( load_image,PF_RGBA8888 ) Copy(load_image) Flip WaitKey End Function Copy(pix:TPixmap) Local pix_dest:TPixmap=CreatePixmap(pix.width,pix.height,PF_RGBA8888) Local psource:byte Ptr Local pdest:byte Ptr psize=32*4*pix.height*4 For k=0 To pix.width-32 Step 32 psource=PixmapPixelPtr(pix,k,0) pdest=PixmapPixelPtr(pix_Dest,k,0) MemCopy(pdest,psource,psize) Next image:TImage=LoadImage(pix_DEST) DrawImage IMAGE,0,0 End Function |
| ||
Load your pixmap Create a StaticPixmap or use PixmapWindow to `look at an area of that pixmap` You now have a pixmap which contains only the area that you wanted. If you want to take that area and instead of it being shared memory with the whole original pixmap, put it into its own pixmap, then create a new pixmap the size of the area and use that pixmaps pixmap.paste() method. You don't have to go copying every single individual pixel yourself. An alternative is to use ReadPixel() and WritePixel() in your loops. |
| ||
Oh thanks very much! |
| ||
Yeah, the pixmap window and paste methods are very useful and should be better publicized... |