resizing images 2


M

Mike P

I am working from this example to resize an image :

http://aspnet.4guysfromrolla.com/articles/012203-1.2.aspx

I have converted most of the code to C# :

Response.Clear();
Response.ContentType = "image/jpeg";

System.Drawing.Image image = retrieveImage(strEncodedImage);

System.Drawing.Image.GetThumbnailImageAbort dummyCallback;

dummyCallback = new
System.Drawing.Image.GetThumbnailImageAbort(new
EventHandler(ThumbnailCallback));

System.Drawing.Image thumb;

thumb = image.GetThumbnailImage(600, 350, dummyCallback,
IntPtr.Zero);

thumb.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg);

But I'm not sure what to do with this :

Function ThumbnailCallback() as Boolean
Return False
End Function

Can anybody help?
 
Ad

Advertisements

P

PvdG42

Mike P said:
I am working from this example to resize an image :

http://aspnet.4guysfromrolla.com/articles/012203-1.2.aspx

I have converted most of the code to C# :

Response.Clear();
Response.ContentType = "image/jpeg";

System.Drawing.Image image = retrieveImage(strEncodedImage);

System.Drawing.Image.GetThumbnailImageAbort dummyCallback;

dummyCallback = new
System.Drawing.Image.GetThumbnailImageAbort(new
EventHandler(ThumbnailCallback));

System.Drawing.Image thumb;

thumb = image.GetThumbnailImage(600, 350, dummyCallback,
IntPtr.Zero);

thumb.Save(Response.OutputStream,
System.Drawing.Imaging.ImageFormat.Jpeg);

But I'm not sure what to do with this :

Function ThumbnailCallback() as Boolean
Return False
End Function

Can anybody help?

I'm not sure I understand your question, but:

Function ThumbnailCallback() as Boolean
Return False
End Function

is a simple method that takes no arguments and returns a Boolean. Unless
there's more context to justify it (is it called from multiple statements?),
it's trivial, because all it does is return false unconditionally.

Your statement that calls ThumbnailCallback():

System.Drawing.Image.GetThumbnailImageAbort(new
EventHandler(ThumbnailCallback));

Needs () after the method name.

System.Drawing.Image.GetThumbnailImageAbort(new
EventHandler(ThumbnailCallback()));
 
P

Peter Duniho

[...]
Your statement that calls ThumbnailCallback():

System.Drawing.Image.GetThumbnailImageAbort(new
EventHandler(ThumbnailCallback));

Needs () after the method name.

System.Drawing.Image.GetThumbnailImageAbort(new
EventHandler(ThumbnailCallback()));

No, that's not correct.

The statement you've quoted doesn't _call_ the method
ThumbnailCallback(). It references that method during the creation of a
delegate instance. Changing the statement so that it calls the method
won't "fix" it (that part wasn't broken in the first place).

Unfortunately, the OP has spread this one question over several different
message topics, so it's difficult to keep up with what he's doing. In a
later message, he (as near as I can tell) essentially repeats this
question, but then followed up, writing that he'd found a solution. (He
didn't bother to show any of the C# code he's actually having trouble
with, but I'm guessing based on his comments that he failed to implement
the "ThumbnailCallback()" method correctly in C#, and has since corrected
that problem).

As far as the specific issue here goes, the fundamental goal the OP
appears to have is to call the Image.GetThumbnailImage() method, which has
a required delegate type argument that is actually unused by the method
but (according to the documentation) is still required to be present and
non-null. The MSDN documentation has a perfectly useful C# sample for
calling this method:
http://msdn.microsoft.com/en-us/library/system.drawing.image.getthumbnailimage.aspx

The one possible refinement I might make is to do away with the named
"dummy" method, and instead just use an anonymous method in its stead.
From the MSDN example, instead of:

Image myThumbnail = myBitmap.GetThumbnailImage(40, 40, myCallback,
IntPtr.Zero);

I would use:

Image myThumbnail = myBitmap.GetThumbnailImage(40, 40, () => false,
IntPtr.Zero);

Where a lambda expression is used to create an anonymous method that
simply returns false.

Pete
 
Ad

Advertisements

P

PvdG42

Peter Duniho said:
No, that's not correct.

The statement you've quoted doesn't _call_ the method
ThumbnailCallback(). It references that method during the creation of a
delegate instance. Changing the statement so that it calls the method
won't "fix" it (that part wasn't broken in the first place).

Unfortunately, the OP has spread this one question over several different
message topics, so it's difficult to keep up with what he's doing. In a
later message, he (as near as I can tell) essentially repeats this
question, but then followed up, writing that he'd found a solution. (He
didn't bother to show any of the C# code he's actually having trouble
with, but I'm guessing based on his comments that he failed to implement
the "ThumbnailCallback()" method correctly in C#, and has since corrected
that problem).

As far as the specific issue here goes, the fundamental goal the OP
appears to have is to call the Image.GetThumbnailImage() method, which has
a required delegate type argument that is actually unused by the method
but (according to the documentation) is still required to be present and
non-null. The MSDN documentation has a perfectly useful C# sample for
calling this method:
http://msdn.microsoft.com/en-us/library/system.drawing.image.getthumbnailimage.aspx

The one possible refinement I might make is to do away with the named
"dummy" method, and instead just use an anonymous method in its stead.
From the MSDN example, instead of:

Image myThumbnail = myBitmap.GetThumbnailImage(40, 40, myCallback,
IntPtr.Zero);

I would use:

Image myThumbnail = myBitmap.GetThumbnailImage(40, 40, () => false,
IntPtr.Zero);

Where a lambda expression is used to create an anonymous method that
simply returns false.

Pete

Thanks for the correction and clarification. I should have looked through
the OP's reference before responding.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top