html - Adding footer to image in C# -
i using getusermedia api capture image , draw canvas. using todataurl() of canvas "imageurl". url saved png image local file. looking before saving image add comment image @ bottom of image(not on image) footer. have below code. can 1 suggest me how in c#.
imagebyte= convert.frombase64string(imageurl); using (var streambitmap = new memorystream(imagebyte)) { using (var img = image.fromstream(streambitmap)) { img.save(localpath); } }
you can create new bitmap higher original image fit footer below. next copy original image , footer bitmap , save new bitmap.
the method (assuming footer width <= image width):
public bitmap appendimagefooter(system.drawing.image bmp, system.drawing.image footer) { //create new image bigger original image make place footer bitmap newimage = new bitmap(bmp.height+footer.height,bmp.width); //get graphics new image , copy original image , next footer below graphics g = graphics.fromimage(newimage); g.drawimage(bmp, new point(0, 0)); g.drawimage(footer, new point(0, bmp.height)); g.dispose(); return newimage; }
and can fit in code @ place:
var footer = image.fromfile("path_to_your_footer.png"); imagebyte= convert.frombase64string(imageurl); using (var streambitmap = new memorystream(imagebyte)) { using (var img = image.fromstream(streambitmap)) { var imagewithfooter = appendimagefooter(img, footer); imagewithfooter.save(localpath); } }
edited in reply additional question comments:
you can build footer in runtime. sample code below, of course can draw whatever in whatever style like:
public bitmap appendimagefooter(system.drawing.image bmp, string text) { //create new image bigger original image make place footer bitmap newimage = new bitmap(bmp.height+200,bmp.width); //get graphics , copy image , below footer graphics g = graphics.fromimage(bmp); g.drawimage(bmp, new point(0, 0)); g.fillrectangle(new solidbrush(color.black), 0, bmp.height, bmp.width, 200); g.drawstring(text, new font("arial", 14), new solidbrush(color.white), 20, bmp.height + 20); //anything else like, circles, rectangles, texts etc.. g.dispose(); return newimage; }
Comments
Post a Comment