asp.net - datatype image in $.ajax -
in page cap.aspx
==========================================================================
string code = getrandomtext(); bitmap bitmap = new bitmap(160,50,system.drawing.imaging.pixelformat.format32bppargb); graphics g = graphics.fromimage(bitmap); pen pen = new pen(color.lavenderblush); rectangle rect = new rectangle(0,0,160,50); solidbrush b = new solidbrush(color.lightpink); solidbrush blue = new solidbrush(color.white); int counter = 0; g.drawrectangle(pen, rect); g.fillrectangle(b, rect); (int = 0; < code.length; i++) { g.drawstring(code[i].tostring(), new font("tahoma", 10 + rand.next(14, 18)), blue, new pointf(10 + counter, 10)); counter += 20; } drawrandomlines(g); bitmap.save(response.outputstream,imageformat.gif); g.dispose(); b.dispose(); blue.dispose(); bitmap.dispose(); ===================================================================================
<div id="divdialog" style="display:none"> <img src="cap.aspx"/> </div> ===================================================================================
$("#divdialog").dialog(); ================================================================================== show dialog not show image? address cap.aspx correct!
how cap.aspx $.ajax , datatype:image?
i think key here add contenttype , bufferoutput
context.response.contenttype = "image/gif"; context.response.bufferoutput = false; eg:
public void renderit(httpcontext context) { context.response.contenttype = "image/gif"; context.response.bufferoutput = false; string code = getrandomtext(); using(bitmap bitmap = new bitmap(160,50,system.drawing.imaging.pixelformat.format32bppargb)) { using(graphics g = graphics.fromimage(bitmap)) { using(pen pen = new pen(color.lavenderblush) { using(solidbrush b = new solidbrush(color.lightpink)) { using(solidbrush blue = new solidbrush(color.white)) { rectangle rect = new rectangle(0,0,160,50); int counter = 0; g.drawrectangle(pen, rect); g.fillrectangle(b, rect); (int = 0; < code.length; i++) { g.drawstring(code[i].tostring(), new font("tahoma", 10 + rand.next(14, 18)), blue, new pointf(10 + counter, 10)); counter += 20; } drawrandomlines(g); g.dispose(); b.dispose(); blue.dispose(); // return bitmap.save(context.response.outputstream, imageformat.gif); // dispose bitmap.dispose(); } } } } } context.response.end(); }
Comments
Post a Comment