Solved

SHOW DIFFERENT SIZE OF IMAGE FILE TO DATAGRIDVEW

Posted on 2011-02-12
11
298 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Set form below another form 3 35
Format column on datatable 7 28
Red error squiggly on vb.net 7 27
Populating an array of locale_time_info 8 37
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

914 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now