Solved

SHOW DIFFERENT SIZE OF IMAGE FILE TO DATAGRIDVEW

Posted on 2011-02-12
11
300 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

778 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