Merging 2 images using C# -
i want merge 2 pictures in c# program. first 1 picture in grayscale mode, , second 1 in picture:
both of pictures/images have same size, , code:
bitmap first = new bitmap (picturebox1.image); bitmap second = new bitmap (picturebox2.image); bitmap result = new bitmap (first.width, first.height); graphics g = graphics.fromimage(result); g.drawimageunscaled(first, 0, 0); g.flush(); g.drawimageunscaled(second, 0, 0); g.flush(); picturebox3.image = result;
i can join picture, result has smaller size 2 originals (both pictures have same size). give me suggestions?
additionally, want result picture has condition : if edge pixel in 2nd picture dropped bright side @ 1st one, dark, otherwise when edge dropped dark side, bright (seem glow). text semi transparent.
here's example of results want.
could give suggestions please?
it joining
bitmap first = new bitmap (picturebox1.image); bitmap second = new bitmap (picturebox2.image); bitmap result = new bitmap (first.width+first.width, first.height); graphics g = graphics.fromimage(result); g.drawimageunscaled(first, 0, 0); g.drawimageunscaled(second,first.width, 0);
try merging 1 on top . set alpha ( red: u can use bitmap.maketransparent if u not want alpha)
public bitmap setimageopacity(image image, float opacity) { try { //create bitmap size of image provided bitmap bmp = new bitmap(image.width, image.height); //create graphics object image using (graphics gfx = graphics.fromimage(bmp)) { //create color matrix object colormatrix matrix = new colormatrix(); //set opacity matrix.matrix33 = opacity; //create image attributes imageattributes attributes = new imageattributes(); //set color(opacity) of image attributes.setcolormatrix(matrix, colormatrixflag.default, coloradjusttype.bitmap); //now draw image gfx.drawimage(image, new rectangle(0, 0, bmp.width, bmp.height), 0, 0, image.width, image.height, graphicsunit.pixel, attributes); } return bmp; } catch (exception ex) { return null; } } private void button1_click(object sender, eventargs e) { bitmap first = new bitmap(picturebox1.image); bitmap second = setimageopacity(picturebox2.image, 0.5f); //bitmap result = new bitmap(first.width, first.height); //fix : bitmap result = new bitmap(math.max(first.width,second.width), math.max(first.height,second.height)); console.writeline(first.width); graphics g = graphics.fromimage(result); g.drawimageunscaled(first, 0, 0); g.drawimageunscaled(second, 0, 0); picturebox3.image = result; result.save("result.jpg" ); } } }
and coming watermark why not want use drawstring alpha here article these http://www.codeproject.com/articles/5034/how-to-implement-alpha-blending
Comments
Post a Comment