Click here to Skip to main content
14,421,753 members
Rate this:
Please Sign up or sign in to vote.
See more:

This is venkat..

I have an issue when rotate images which are exist in remote system..

I have written the following code for image rotation in handler page..

The below code is not working ..Please help me on this issue as early as possible..

public void ProcessRequest(HttpContext context)
    string Path = context.Request.Form["Path"];
    int width = int.Parse(Convert.ToString(context.Request.Form["Width"]));
    int height = int.Parse(Convert.ToString(context.Request.Form["Height"]));

    //Create Request to get Image stream
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Path);
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    Stream receiveStream = response.GetResponseStream();
    Image theImage = System.Drawing.Image.FromStream(receiveStream);

    context.Response.ContentType = "image/jpeg";
    theImage.Save(context.Response.OutputStream, ImageFormat.Jpeg);

    context.Response.ContentType = "text/plain";
    context.Response.Charset = "";
Updated 14-Nov-12 9:32am
CafedeJamaica 14-Nov-12 14:33pm
Whats the error message?
K.Venkateswarlu 14-Nov-12 14:35pm
i am not getting error message..
the image not rotating..
jkirkerx 15-Nov-12 1:55am
So your trying to take a snapshot of a webpage and rotate it?

I may be wrong on this, but I think your missing the webpage to image conversion part. Then rotate it.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I was wrong. At the core, you're doing everything wrong. You need to use Server.MapPath to get the path to the file, and use that path to save it, unless your HTTPHandler is being used correctly ( to find and process a file, the URL being the src part of an img tag ).
K.Venkateswarlu 14-Nov-12 16:19pm
Actually the image in remote system not in local system so when i call this handler page by post method using j-query the code is executing fine...but the image is not rotating...
Christian Graus 14-Nov-12 16:20pm
Read it again.....
K.Venkateswarlu 14-Nov-12 16:22pm
you have written theImage = theImage.Rotate... like this
but the Rotateflip method won't return anything..
Christian Graus 14-Nov-12 16:23pm
You are right. Then this code is not running. I bet the browser is caching the image
K.Venkateswarlu 14-Nov-12 16:26pm
then how can i solve the issue..
K.Venkateswarlu 14-Nov-12 16:29pm
suppose can i save this flipped image into some another place..can i have chance..?
Christian Graus 14-Nov-12 16:30pm
No, I don't think it matters. You need to mark the page calling this URL to not cache anything
K.Venkateswarlu 14-Nov-12 16:32pm
how can do that..?
K.Venkateswarlu 14-Nov-12 16:36pm
I mean where i have to written the code for that..
Christian Graus 14-Nov-12 16:46pm
I think we need to see the web page that calls this HTTP Handler to comment more. Sorry, I was wrong about it returning the object, so I can only think the page is caching it. The other thing you can do, is create a new file name, where a suffix tells you the operation, then parse that out, and perform it. For example if my.jpg became my.90XY.jpg and you worked out that maps to my.jpg with a 90 degree rotate and XY flip, then the filename would be different and there would be no cache
Christian Graus 14-Nov-12 16:47pm
K.Venkateswarlu 14-Nov-12 16:52pm
Still the image displaying same...
K.Venkateswarlu 14-Nov-12 16:53pm
i have used like this..

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Views/Shared/BluePrint.XMPoint.Master"
CodeBehind="XlimUI.aspx.cs" Inherits="BluePrint.XMPoint.Views.Dummy.XlimUI" %>

<%@ MasterType VirtualPath="~/Views/Shared/BluePrint.XMPoint.Master" %>
<%@ Register Assembly="InlineJScript" Namespace="InlineJScript" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE">
Christian Graus 14-Nov-12 16:55pm
The meta tag goes in your master page, in the 'head' section of the page. Where is the image in all this ? How is it being set ?
K.Venkateswarlu 14-Nov-12 16:56pm
My javascript/j-query code like this..

var Parameters = "Path=" + src + "&Width=" + width + "&Height=" + height;
type: "POST",
url: "ImgRotater.ashx",
data: Parameters,
success: function (msg) {

$('#Actimg').attr('src', msg);
var response = JSON.parse(msg);
if (response.status == "completed") {
//done with proofs
var Url = eval(Url.decode(response.url));
$('#' + ActiveImageId).attr('src', Url);

else if (response.status == "pending") {

setTimeout('RotateImage(' + Parameters + ')', 100);
else {
alert('proof error');
error: function (xhr, msg) {
var response = JSON.parse(xhr.responseText);
K.Venkateswarlu 14-Nov-12 16:57pm
Please let me know why still i am getting the same issue..
Christian Graus 14-Nov-12 16:59pm
This won't work. Rotating the image on the server won't force the client to reload it. It's rotating on the server, but the client keeps showing the same image. You need, after your rotate call, to clear the image, and then reload it. Setting it to be what it was, the browser will probably ignore that. I'd suggest removing the img tag and reinserting it, to be sure
K.Venkateswarlu 14-Nov-12 16:59pm
the image rotation is not in master page..
Christian Graus 14-Nov-12 17:00pm
I know. So what ? It's one page to the client, and the client reads the meta tag from the head. I think you need to read some books on how the web works. In the meantime, that is not the issue, now I've seen your code, the issue is what I said above. You're not loading the image, only rotating it on the server.
K.Venkateswarlu 14-Nov-12 17:00pm
ok i will try that..
K.Venkateswarlu 14-Nov-12 17:13pm
i have tried to create once again the img tag but still it displays same..

suppose it rotating in server when i open the image in server it will be open in rotate mode right..? but the image not rotated in the server..
Christian Graus 14-Nov-12 17:15pm
Have you opened the image you saved on the server ? Is it rotated ?
Christian Graus 14-Nov-12 17:15pm
Have you set break points to see what happens when the code is called ?
K.Venkateswarlu 14-Nov-12 17:19pm
theImage.Save(context.Response.OutputStream, ImageFormat.Jpeg);

is the above code saves the rotated image in the path right..?
K.Venkateswarlu 14-Nov-12 17:21pm
i have the image path and i have just opened in a browser but it shows the same image..
K.Venkateswarlu 14-Nov-12 17:24pm
i have debug the source code i think the flipped image is not saving in the path...
K.Venkateswarlu 14-Nov-12 17:24pm
Please help me on this..
Christian Graus 14-Nov-12 17:25pm
Got it. Your code is broken in so many ways. You're writing a HTTP Handler. This typically means that the image gets rotated when it's requested, your code runs and returns the image. However, if you're using jquery to call the method that does the rotating, then nothing is paying attention to the return value, which is the stream you are writing to. You need to save it to the file system, or change your code so you tell it how to rotate it every time, because the file on the server is never changed. I would suggest that is the best way to do it ( do what I suggested above and use the HTTP handler properly, by having the file name tell you what operation to do, and the operation is triggered by setting a file name that includes the trigger, which fires the HTTP handler and displays the image. The cheap way is to save the image to the file system ( using the path you used to load it ) and have it constantly change on the server itself.
Christian Graus 14-Nov-12 17:26pm
Also, I think I've shown my willingness to keep trying to help you. When you ask something, wait, don't post 'please help me' every time.
K.Venkateswarlu 14-Nov-12 17:29pm
i have tried to save the image using path but it returns an error..
the error message is "Uri format not supported."
Christian Graus 14-Nov-12 17:31pm
You really do have no idea what you're doing. Use Server.MapPath to get a local path for a file. I'm surprised you could load it without doing that, but you shouldn't.
K.Venkateswarlu 14-Nov-12 17:43pm

i have the image in the above path it is in network drive not in local how can i write server.mappath...?

i have just used the path for saving.. for that i have written the code like this..

theImage.Save(Path, ImageFormat.Jpeg);

it returns "Uri format not supported."
Christian Graus 14-Nov-12 17:53pm
If you're accessing the file from a network, then you need to go with my #1 solution. Your img tag has a src which is a URL to a web page or triggers a HTTP handler, which finds the image and processes it and returns the image bytes to the img tag.
K.Venkateswarlu 14-Nov-12 18:01pm
ok..i understood that but here i have multiple img tags.. and at runtime i will select any one of the img tag then i will click rotate button then i need rotate image to display...
Christian Graus 14-Nov-12 18:48pm
Hence the image name you pass to the handler being a combination of the image name and a rotate instruction

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100