Solved

SHOW DIFFERENT SIZE OF IMAGE FILE TO DATAGRIDVEW

Posted on 2011-02-12
11
297 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

18 Experts available now in Live!

Get 1:1 Help Now