Link to home
Start Free TrialLog in
Avatar of G0ggy
G0ggyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Create Image Thumbnail - Display in GridView

Hi All,

I'm trying to create a thumbnail from an existing banner image, to display to the users in a GridView.

Here's the template field from the GridView:

<asp:TemplateField>
                <ItemTemplate>
                    <%# GetThumbnailImage(Eval("ImageName")) %>
                </ItemTemplate>
            </asp:TemplateField>

Open in new window


Here's the GetThumbnailImage function:

        public static string GetThumbnailImage(object ImageName)
        {
            string imageName = ImageName.ToString();
            MicrositeBanners myMB = new MicrositeBanners();

            byte[] imageBytes = myMB.ThumbnailImage(imageName);

            return imageBytes;
        }

Open in new window


And here's the code to create the thumbnail:

        public byte[] ThumbnailImage(string file)
        {
            Image image = Image.FromFile(HttpContext.Current.Server.MapPath(file));
            Image thumbnail = image.GetThumbnailImage(64, 64, new Image.GetThumbnailImageAbort(ThumbnailCallBack), IntPtr.Zero);

            MemoryStream imageStream = new MemoryStream();

            thumbnail.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] imageContent = new Byte[imageStream.Length];

            imageStream.Position = 0;

            imageStream.Read(imageContent, 0, (int)imageStream.Length);

            return imageContent;
        }

        public bool ThumbnailCallBack()
        {
            return true;
        }
    }

Open in new window


I can't tell you yet whether the thumbnail is being succesfully created as I'm having trouble getting the Byte array that returned to display in the GridView.

Currently I'm getting a "cannot convert byte array to string" error.

Any ideas how to achieve this?

Thanks.
Avatar of kaufmed
kaufmed
Flag of United States of America image

You GetThumbnailImage method is declared to return a string, but you are returning a byte array. Why is that?

public static string GetThumbnailImage(object ImageName)
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of G0ggy

ASKER

I've requested that this question be deleted for the following reason:

Unresolved, neither suggestion worked.
Which part did not work?
Please post your code implementing my comments to have a look.

I just did a quick test of my proposed solution using VS2010 /IIS 7 and it works OK.
Avatar of G0ggy

ASKER

No it's not solved and it is precisely abandoned. I think, in the end, a different method was chosen - outside of using a GridView. For leaving it so long I apologise, but I cannot accept an answer provided here as these didn't work at the time.

I tried to bring a conclusion to the problem as I needed to ask another question and your system would not allow me too, a slight quandary and pretty annoying considering we pay for this service.
@GOggy
Keep in mind that as a volunteer, my time is as valuable as yours. You are just trying to close the question without given the posts a chance to just to solve your next question issue.
The answer was based on your question. I am not mind reader otherwise I will be in the stock market not here...
@Moderator: Delete with no refund, as the question does not add any value other than wasting our time
Avatar of G0ggy

ASKER

Hold on a cotton-picking second here, I said the answers didn't work, work projects move on and partly I did forget about the question on here.

When the website was finished I think we just put a manual image control - I really can't remember and at the moment I'm at home.

Although I appreciate your time, it's a simple question with some points for answering - if it bothers you that much to lose out on your valuable virtual points, I'll accept your answer. To be quite frank, as stated, it was merely to get the question posting restriction removed.

I original joined EE some years ago when it used to be pretty fun to help people out, since that time the bickering that goes on over points allocation was the reason why we never really bothered with it. After some cut-backs in work we decided it might be useful again, yet I see nothing has changed. Our subscription ran out today - funnily enough, we shall not renewing.

Stack Exchange has its fair share of problems, but it's a damn sight less stuck up its own posterior.
Avatar of G0ggy

ASKER

Enjoy!