Hi Guys/Girls (if there any here
!
I trying to "paste" one small picture into another( much bigger one) using MemblockFromImage. Problem is that "pasted" image is much different that original one (see pastedimage.bmp in attachment). Could you tell me what I'm doing wrong? I don't want to simply sprite it somewhere on the screen, I want to modify existing background image by changing some of it's pixels equal to smaller picture pixels. I hope you know what I mean. Basically I will be using it for example making stamps/marks of blood/enemy bodies on background etc. If I will use sprite for that it's will use a lot of memory so I thing that's the best solution. I will be very glad if some will help me with it, I spent loads of time trying to find where problem is and now I'm really desperate
. That's code what I using at the moment, and in attachment there are 2 pictures witch I'm using (background and square). Third picture is an image of "pasted" square into background. Thanks! :
#include "DarkGDK.h"
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60
);
dbLoadImage("background.jpg",1); //simple bacground image 1024X1024
dbLoadImage("square.bmp",2); //simple square image, 20x20, red frame, white inside
dbSprite(1,0,0,1); //pasting background
//---------------------------------------------------------------------------------------------------
// MAIN LOOP - MAIN LOOP - MAIN LOOP - MAIN LOOP - MAIN LOOP - MAIN LOOP
//---------------------------------------------------------------------------------------------------
while ( LoopGDK ( ) )
{
dbMakeMemblockFromImage(1,1); //making memblock from background bitmap
dbMakeMemblockFromImage(2,2); //making memblock from square bitmap
int B_width = dbMemblockDWORD(1,0); //reading background width
int S_width = dbMemblockDWORD(2,0); //reading square width
int S_height = dbMemblockDWORD(2,4); //reading square height
for(int x=1;x<=S_width;x++)
{
for(int y=1;y<=S_height;y++)
{
int S_pixel_loc = ((y-1)*S_width + x - 1)*4 + 12; //reading pixel location according to X and Y - SOURCE
int S_blue = dbMemblockByte(2,S_pixel_loc); //reading blue value of current pixel
int S_green = dbMemblockByte(2,S_pixel_loc+1); //reading green value of current pixel
int S_red = dbMemblockByte(2,S_pixel_loc+2); //reading red value of current pixel
DWORD S_pixelcolor = dbRGB(S_red,S_green,S_blue); //creating DWORD holding RGB info of current pixel
int xpaste = 100+x; //x paste position
int ypaste = 100+y; //y paste position
int B_pixel_loc = ((ypaste-1)*B_width + xpaste - 1)*4 + 12; //reading pixel location according to xpaste and ypaste - TARGET
dbWriteMemblockDWORD(1,B_pixel_loc,S_pixelcolor); //writing SOURCE pixel from square bitmap into backgroung TARGET pixel
}
}
dbMakeImageFromMemblock(1,1);
dbSync ();
}
return;
}
//---------------------------------------------------------------------------------------------------
// END OF MAIN LOOP - END OF MAIN LOOP - END OF MAIN LOOP - END OF MAIN LOOP
//---------------------------------------------------------------------------------------------------