Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SHOW DIFFERENT SIZE OF IMAGE FILE TO DATAGRIDVEW

Posted on 2011-02-12
11
Medium Priority
?
310 Views
Last Modified: 2012-08-13
Hi All,

I want to show image to datagridview, the problem is there have different size. Some small, some very big.

How could we manage it ?

Thank you.

0
Comment
Question by:emi_sastra
  • 5
  • 3
  • 3
11 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34883466
What do you want to do then? Resize the large ones to match the small ones?
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 34884999
Something like that.


Thank you.
0
 
LVL 22

Expert Comment

by:Mrunal
ID: 34885392
Here is the logic you can use:

you have to fix minimum height or width. e.g. 100px.
then check height and width of current image you have to display.

if height > width then
  if height > 100 then
    make height = 100 and proportionate width according to height.
  else
    display image as it is with default height and width.
else
  if width > 100 then
    make width = 100 and proportionate height according to width.
  else
    display image as it is with default height and width.


Hope you get idea what i mean.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:emi_sastra
ID: 34885420
Hi mroonal,

Please see below code.


  Image1 = System.Drawing.Image.FromFile(fi.FullName)

  Dim dgvImagCell As DataGridViewImageCell = New DataGridViewImageCell()
                        'dgvImagCell.ImageLayout = DataGridViewImageCellLayout.Stretch
                        dgvImagCell.Value = Image1
                        dgvRow.Cells.Add(dgvImagCell)

How to apply your idea ?

Thank you.
0
 
LVL 22

Expert Comment

by:Mrunal
ID: 34885495
ohh. you are using DataGridViewImageCell.
try by setting newly calculated height and width to Image1 and remove that layout as Stretch.

Otherwise better way add simple image in template field and assign newly calculated height and width to that image.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 34885621
Would you please provide code, I still have no clear idea how to do it.

Thank you.
0
 
LVL 22

Expert Comment

by:Mrunal
ID: 34885733
here it is:

Declare image in TemplateField as:
If you have image url in your datasource which you are binding to gridview then no need to call function completedImage(). directly assign image path there.
Otherwise call this fuction to assign image url.

<asp:TemplateField HeaderText="Status" ItemStyle-HorizontalAlign="Center">
               <ItemTemplate>
               <asp:Image ID="completedImage" runat="server" ImageUrl="<% # completedImage() %>" AlternateText=""/>
               </ItemTemplate>
               </asp:TemplateField>


then on RowCreated event of grid view acces that image and assign newly calculated height and width.

here is reference link:

http://forums.asp.net/p/1342597/2721342.aspx#2721342

http://www.asp.net/data-access/tutorials/using-templatefields-in-the-gridview-control-cs

Hope this helps you.
Pl. let me know if still you need something more.
0
 
LVL 1

Author Comment

by:emi_sastra
ID: 34885799
I use windows form.

Thank you.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 34886594
Try this code




Image1 = System.Drawing.Image.FromFile(fi.FullName)
Dim dgvImagCell As DataGridViewImageCell = New DataGridViewImageCell()
dgvImagCell.Value = Image1.GetThumbnailImage(120, 90, AddressOf ImageThumbnailCallback, IntPtr.Zero)
dgvRow.Cells.Add(dgvImagCell)


'You would need to copy this sub as well
Private Function ImageThumbnailCallback() As Boolean
End Function

Open in new window

0
 
LVL 1

Author Comment

by:emi_sastra
ID: 34922333
Hi CodeCruiser.

I am so sorry, just back again, I have frustrateed using datagridview to show it and change to flowlayoutpanel.

I try again, and it works great, very surprising.

Thank you very much for your help.


0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 34924627
Glad to help :-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Screencast - Getting to Know the Pipeline

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question