Handler.ashx -> return picture

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
pdusp
Posts: 1
Joined: 09 May 2012, 16:13

Handler.ashx -> return picture

Post by pdusp » 09 May 2012, 16:42

Hello,
I am going to buy CadSoftTools but I have to test it before.
Please help me finish my job.
I have to create ashx file for web service. It should produce image for a given dxf file.
What I need is a good idea how to receive and return picture designed by Cad library.
On output I need image context.Response.WriteFile( takeCad() ); but now is problem.
I attached my ashx file.
Thank you dear friends!
Piotr



<%@ WebHandler Language="C#" Class="Handler" %>
using System.Drawing.Imaging;
using System;
using System.Web;
using CADImport;
using CADImport.RasterImage;
using CADImport.DWG;



public class Handler : IHttpHandler {

public void ProcessRequest (HttpContext context) {
// context.Response.ContentType = "text/plain";
// context.Response.Write("Hello World");

string loc = "~/APQP_na.bmp";

context.Response.ContentType = "image/gif";
//context.Response.WriteFile( takeCad() );



}

private string outFileName = @"testasp3.gif";
private CADImage cadImage;
DRect boundaryRectangle;
int left=0;
int top=0;
int width=550;
int height=550;
string inFileName="test.dxf";



public CADImage takeCad()

{
boundaryRectangle = new DRect(left, top, width, height);
cadImage = CADImage.CreateImageByExtension(inFileName);

cadImage.UseDoubleBuffering = false;
cadImage.LoadFromFile(inFileName);

ImageFormat imgFrm = ImageFormat.Gif;

cadImage.ChangeDrawMode(DrawGraphicsMode.GDIPlus, null);

cadImage.BorderSize = 0;
cadImage.DrawMode = CADDrawMode.Black;

System.Drawing.Rectangle rect = new System.Drawing.Rectangle((int)left, (int)top, (int)width, (int)height);

return (cadImage);


}


public bool IsReusable {
get {
return false;
}
}

}

Thank you
http://www.EuroDolar.pl

support
Posts: 3272
Joined: 30 Mar 2005, 11:36
Contact:

Re: Handler.ashx -> return picture

Post by support » 11 May 2012, 11:19

Hello.
.NET Framework provides System.Drawing.Bitmap class that represents a raster image object. Use CADImage.SaveToFile or CADImage.SaveToStream then instantiate an object of Bitmap class by created file or stream.

Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply