Solved

SHOW DIFFERENT SIZE OF IMAGE FILE TO DATAGRIDVEW

Posted on 2011-02-12
11
305 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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