![]() Background |
![]() Text ![]() Shadow |
![]() Result |
' ........... The function ........... Private Sub mnutext_with_shadow_on_background_Click() Dim tmptext As imgdes Dim tmpshadow As imgdes Dim resimg As imgdes Dim rcode, captionHt, captionWd, txtStartY As Long Dim caption As String Dim count As Long Dim filename As String Dim jinfo As JpegData Dim bpp As Long Dim transcolor As Long filename = "backgrnd.jpg" transcolor = 255 rcode = jpeginfo(filename, jinfo) If (rcode = NO_ERROR) Then rcode = allocimage(resimg, jinfo.width, jinfo.length, jinfo.vbitcount) If (rcode = NO_ERROR) Then rcode = loadjpg(filename, resimg) If (rcode <> NO_ERROR) Then ' Problem loading the background image freeimage resimg Return End If End If End If bpp = jinfo.vbitcount caption = "River" ' Create the shadow in tmpshadow rcode = allocimage(tmpshadow, 176, 86, bpp) If (rcode = NO_ERROR) Then rcode = zeroimage(255, tmpshadow) End If tmpshadow.stx = 7 ' Offset the shadow by (7, 7) tmpshadow.sty = 7 rcode = addtext(808080h, 48, "ARIAL BOLD", caption, tmpshadow) rcode = gaussianblur(15, tmpshadow, tmpshadow) ' Make the shadow fuzzy tmpshadow.stx = 0 tmpshadow.sty = 0 ' Shadow is in tmpshadow, save it so you can examine it later rcode = savejpg("tmpshadow.jpg", tmpshadow, 75) Create the text in tmptext rcode = allocimage(tmptext, 176, 86, bpp) If (rcode = NO_ERROR) Then rcode = zeroimage(255, tmptext) End If rcode = addtext(&h808080, 48, "ARIAL BOLD", caption, tmptext) ' Text is in tmptext, save it so you can examine it later rcode = savejpg("tmptext.jpg", tmptext, 75) ' Put shadow on the background rcode = multiplyimage(resimg, tmpshadow, resimg) If (rcode = NO_ERROR) Then ' Put text over the shadow on the background rcode = multiplyimage(resimg, tmptext, resimg) End If rcode = savejpg("new.jpg", resimg, 75) ' Save the result freeimage tmptext freeimage tmpshadow freeimage resimg End Sub
int text_with_shadow_on_background(void)
{
imgdes tmptext;
imgdes tmpshadow;
imgdes resimg;
int rcode = NO_ERROR, captionHt, captionWd, txtStartY;
char *caption="River";
char *filename = "backgrnd.jpg";
JpegData jinfo;
int bpp;
rcode = jpeginfo(filename, &jinfo);
if(rcode == NO_ERROR) {
rcode = allocimage(&resimg, jinfo.width, jinfo.length, jinfo.vbitcount);
if(rcode == NO_ERROR) {
rcode = loadjpg(filename, &resimg);
if(rcode != NO_ERROR) { // Problem loading the background image
freeimage(&resimg);
return(rcode); // Return error code
}
}
}
bpp = jinfo.vbitcount;
// Create the shadow in tmpshadow
rcode = allocimage(&tmpshadow,176, 86, bpp);
if(rcode == NO_ERROR)
zeroimage(255, &tmpshadow);
tmpshadow.stx = 7; // Offset the shadow by (7, 7)
tmpshadow.sty = 7;
rcode = addtext(0x808080, 48, "ARIAL BOLD", caption, &tmptext);
gaussianblur(15, &tmpshadow, &tmpshadow);
// Shadow is in tmpshadow, save it so you can examine it later
tmpshadow.stx = 0; // Restore origin
tmpshadow.sty = 0;
rcode = savejpg("tmpshadow.jpg", &tmpshadow, 75);
// Create the text in tmptext
rcode = allocimage(&tmptext, 176, 86, bpp);
if(rcode == NO_ERROR)
zeroimage(255, &tmptext);
rcode = addtext(0x808080, 48, "ARIAL BOLD", caption, &tmptext);
// Text is in tmptext, save it so you can examine it later
rcode = savejpg("tmptext.jpg", &tmptext, 75);
// Put shadow on the background
rcode = multiplyimage(&resimg, &tmpshadow, &resimg);
if(rcode == NO_ERROR)
// Put text over the shadow on the background
rcode = multiplyimage(&resimg, &tmptext, &resimg)
rcode = savejpg("new.jpg", &resimg, 75); // Save the result
freeimage(&tmptext);
freeimage(&tmpshadow);
freeimage(&resimg);
return(rcode);
}
Victor Image Processing Library homepage | Victor Product Summary | more source code