Click here to Skip to main content
15,612,452 members
Home / Discussions / C#
   

C#

 
GeneralRe: Write audio to USB Modem via COM Port Pin
ManojKumarShah20175-Nov-17 4:10
ManojKumarShah20175-Nov-17 4:10 
QuestionMultithreaded function calls Pin
Kenneth Haugland4-Nov-17 4:41
professionalKenneth Haugland4-Nov-17 4:41 
AnswerRe: Multithreaded function calls Pin
Sascha Lefèvre4-Nov-17 6:13
professionalSascha Lefèvre4-Nov-17 6:13 
GeneralRe: Multithreaded function calls Pin
Kenneth Haugland4-Nov-17 6:49
professionalKenneth Haugland4-Nov-17 6:49 
GeneralRe: Multithreaded function calls Pin
Sascha Lefèvre4-Nov-17 7:01
professionalSascha Lefèvre4-Nov-17 7:01 
GeneralRe: Multithreaded function calls Pin
Kenneth Haugland4-Nov-17 7:10
professionalKenneth Haugland4-Nov-17 7:10 
GeneralRe: Multithreaded function calls Pin
Sascha Lefèvre4-Nov-17 7:23
professionalSascha Lefèvre4-Nov-17 7:23 
QuestionHow to make the ListView to display each thumbnail immediately after it's loaded? [solved] Pin
alin14-Nov-17 3:02
alin14-Nov-17 3:02 
I have to display thumbnails in a ListView control but the problem is that the control is locked until it finally loads and displays all thumbnails. Is there a simple way to display each thumbnail immediately after its loaded (in the same way Windows Exporer displays thumbnails in real time)?

This is the code for loading ListView with thumbnails:

void LoadListView()
{
    int i = 0;
    listView1.LargeImageList = imageList1;

    foreach (string file in fileList)
    {
        Bitmap thumbnail = MakeThumbnail(file, 200, 200);
        imageList1.Images.Add(thumbnail);
        ListViewItem caption = new ListViewItem(Path.GetFileName(file));
        caption.ImageIndex = i;
        listView1.Items.Add(caption);
        i++;
    }
}


And this is the code for creating thumbnails with the correct aspect ratio:

Bitmap MakeThumbnail(string filename, int thumbWidth, int thumbHeight)
{
  Bitmap thumbnail = null;
  
  try
  {
    Bitmap bmp = new Bitmap(filename);
    ImageFormat loFormat = bmp.RawFormat;
    decimal ratio;
    int newImgWidth = 0;
    int newImgHeight = 0;

    // If the image is smaller than a thumbnail just return it
    if (bmp.Width < thumbWidth && bmp.Height < thumbHeight)	return bmp;

    if (bmp.Width > bmp.Height)
    {
      ratio = (decimal)thumbWidth / bmp.Width;
      newImgWidth = thumbWidth;
      decimal temp = bmp.Height * ratio;
      newImgHeight = (int)temp;
    }
    else
    {
      ratio = (decimal)thumbHeight / bmp.Height;
      newImgHeight = thumbHeight;
      decimal temp = bmp.Width * ratio;
      newImgWidth = (int)temp;
    }
    
    thumbnail = new Bitmap(thumbWidth, thumbHeight);
    Graphics g = Graphics.FromImage(thumbnail);
    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
    g.FillRectangle(Brushes.White, 0, 0, thumbWidth, thumbHeight);
    g.DrawImage(bmp,
                (thumbWidth - newImgWidth) / 2,
                (thumbHeight - newImgHeight) / 2,
                newImgWidth, newImgHeight);

    bmp.Dispose();
  }
  catch
  {
    return null;
  }

  return thumbnail;
}


modified 5-Nov-17 19:25pm.

AnswerRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Dave Kreskowiak4-Nov-17 3:49
mveDave Kreskowiak4-Nov-17 3:49 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 3:51
alin14-Nov-17 3:51 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Dave Kreskowiak4-Nov-17 4:17
mveDave Kreskowiak4-Nov-17 4:17 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 4:06
alin14-Nov-17 4:06 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Dave Kreskowiak4-Nov-17 4:19
mveDave Kreskowiak4-Nov-17 4:19 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 5:57
alin14-Nov-17 5:57 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre4-Nov-17 6:27
professionalSascha Lefèvre4-Nov-17 6:27 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 7:05
alin14-Nov-17 7:05 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre4-Nov-17 7:13
professionalSascha Lefèvre4-Nov-17 7:13 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 7:22
alin14-Nov-17 7:22 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre4-Nov-17 7:25
professionalSascha Lefèvre4-Nov-17 7:25 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 7:30
alin14-Nov-17 7:30 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre4-Nov-17 7:39
professionalSascha Lefèvre4-Nov-17 7:39 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 7:41
alin14-Nov-17 7:41 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre4-Nov-17 7:55
professionalSascha Lefèvre4-Nov-17 7:55 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
alin14-Nov-17 8:23
alin14-Nov-17 8:23 
GeneralRe: How to make the ListView to display each thumbnail immediately after it's loaded? Pin
Sascha Lefèvre4-Nov-17 8:29
professionalSascha Lefèvre4-Nov-17 8:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.