473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Windows-Like thumbnails in ListView?

I'm trying to display thumbnail images in a Listview that look more like the
Windows thumbnail view. Everything is working pretty good, but my
thumbnails are decidedly not like the Windows thumbnails.

View the following snapshot to compare the Windows thumbnails (top) to my
ListView thumbnails (bottom):

http://home.san.rr.com/vagabondia/images/tmp/sample.gif

It looks like the Windows thumbnails retain their proportion by, perhaps,
using some kind of "spacer" image on the top and bottom to create the
"letterbox" effect. I try and maintain the aspect ratio of the original
image, but it stretches into the height and width determined by the
ImageList. Here is my code to get thumbnails from the original images:

--- code ---
thumbnail = getThumbnail(originalImage, imglstStock.ImageSize.Width);

private Image getThumbnail(System.Drawing.Image image, int desiredWidth)
{
int imgWidth = image.Width;
int imgHeight = image.Height;
decimal ratio = (decimal) desiredWidth / imgWidth;
int desiredHeight = Convert.ToInt32(ratio * imgHeight);

Image.GetThumbnailImageAbort thumbCallback = new
Image.GetThumbnailImageAbort(thumbnailCallback);
Image thumb = image.GetThumbnailImage(desiredWidth, desiredHeight,
thumbCallback, IntPtr.Zero);
return thumb;
}

private bool thumbnailCallback()
{
return false;
}
--- code end ---

Any suggestions, advice, or links to reading material would be greatly
appreciated.

Carl
Nov 17 '05 #1
3 11385
You can check the Height/Width of the image returned by getThumbnail
and I bet you'll see that the aspect ratio is correct. What happens is
that Listview stretches your image. Modify your function getThumbnail
to create a square bitmap of the listview thumbnail size, clear it with
white and draw your thumbnail onto it.

One other thing you need to do is to handle vertical images, i.e. those
where height is greater than width

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Vagabond Software" <vagabondsw-X-@-X-gmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I'm trying to display thumbnail images in a Listview that look more like
the Windows thumbnail view. Everything is working pretty good, but my
thumbnails are decidedly not like the Windows thumbnails.

View the following snapshot to compare the Windows thumbnails (top) to my
ListView thumbnails (bottom):

http://home.san.rr.com/vagabondia/images/tmp/sample.gif

It looks like the Windows thumbnails retain their proportion by, perhaps,
using some kind of "spacer" image on the top and bottom to create the
"letterbox" effect. I try and maintain the aspect ratio of the original
image, but it stretches into the height and width determined by the
ImageList. Here is my code to get thumbnails from the original images:

--- code ---
thumbnail = getThumbnail(originalImage, imglstStock.ImageSize.Width);

private Image getThumbnail(System.Drawing.Image image, int desiredWidth)
{
int imgWidth = image.Width;
int imgHeight = image.Height;
decimal ratio = (decimal) desiredWidth / imgWidth;
int desiredHeight = Convert.ToInt32(ratio * imgHeight);

Image.GetThumbnailImageAbort thumbCallback = new
Image.GetThumbnailImageAbort(thumbnailCallback);
Image thumb = image.GetThumbnailImage(desiredWidth, desiredHeight,
thumbCallback, IntPtr.Zero);
return thumb;
}

private bool thumbnailCallback()
{
return false;
}
--- code end ---

Any suggestions, advice, or links to reading material would be greatly
appreciated.

Carl


Nov 17 '05 #2
"Alex Feinman [MVP]" <pu*********@alexfeinman.com> wrote in message
news:O7****************@TK2MSFTNGP15.phx.gbl...
You can check the Height/Width of the image returned by getThumbnail
and I bet you'll see that the aspect ratio is correct. What happens is
that Listview stretches your image. Modify your function getThumbnail
to create a square bitmap of the listview thumbnail size, clear it with
white and draw your thumbnail onto it.

One other thing you need to do is to handle vertical images, i.e. those
where height is greater than width

--


Alex, thanks for the reply. Your suggestions were very helpful and things
are much improved. As you can see in the following sample_v2 screeshot, my
thumbnail images are now identical to the Windows thumbnail images.

http://home.san.rr.com/vagabondia/im.../sample_v2.gif

However, you'll also see that my images are top-justified, which is not what
I wanted. I want them centered, just like the Windows thumbnails. Here is
the code where I try to paint my thumbnail onto a square bitmap image:

--- code ---
/* Height and Width are those of the ImageList.ImageSize.
* Image is the thumbnail being painted onto the background.
*/
private Bitmap preserveAspectRatio(int imgHeight, int imgWidth,
System.Drawing.Image img)
{
Bitmap bmpImage = new Bitmap(imgWidth, imgHeight);
int xoffset = 0;
int yoffset = 0;

if (img.Width > img.Height)
yoffset = getOffset(bmpImage.Height, img.Width);
else
xoffset = getOffset(bmpImage.Width, img.Height) + img.Height;

using(Graphics grafix = Graphics.FromImage(bmpImage))
{
grafix.DrawImage(img, xoffset, yoffset, img.Width, img.Height);
}
return bmpImage;
}
--- code end ---

Your help and advice is greatly appreciated.

Carl
Nov 17 '05 #3
Try

grafix.DrawImage(img, xoffset, yoffset, new Rectangle( 0, 0, img.Width,
img.Height), GraphicUnit.Pixel );

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Vagabond Software" <vagabondsw-X-@-X-gmail.com> wrote in message
news:e4**************@TK2MSFTNGP14.phx.gbl...
"Alex Feinman [MVP]" <pu*********@alexfeinman.com> wrote in message
news:O7****************@TK2MSFTNGP15.phx.gbl...
You can check the Height/Width of the image returned by getThumbnail
and I bet you'll see that the aspect ratio is correct. What happens is
that Listview stretches your image. Modify your function getThumbnail
to create a square bitmap of the listview thumbnail size, clear it with
white and draw your thumbnail onto it.

One other thing you need to do is to handle vertical images, i.e. those
where height is greater than width

--


Alex, thanks for the reply. Your suggestions were very helpful and things
are much improved. As you can see in the following sample_v2 screeshot,
my thumbnail images are now identical to the Windows thumbnail images.

http://home.san.rr.com/vagabondia/im.../sample_v2.gif

However, you'll also see that my images are top-justified, which is not
what I wanted. I want them centered, just like the Windows thumbnails.
Here is the code where I try to paint my thumbnail onto a square bitmap
image:

--- code ---
/* Height and Width are those of the ImageList.ImageSize.
* Image is the thumbnail being painted onto the background.
*/
private Bitmap preserveAspectRatio(int imgHeight, int imgWidth,
System.Drawing.Image img)
{
Bitmap bmpImage = new Bitmap(imgWidth, imgHeight);
int xoffset = 0;
int yoffset = 0;

if (img.Width > img.Height)
yoffset = getOffset(bmpImage.Height, img.Width);
else
xoffset = getOffset(bmpImage.Width, img.Height) + img.Height;

using(Graphics grafix = Graphics.FromImage(bmpImage))
{
grafix.DrawImage(img, xoffset, yoffset, img.Width, img.Height);
}
return bmpImage;
}
--- code end ---

Your help and advice is greatly appreciated.

Carl


Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
2
by: Greg Bacchus | last post by:
Hi, I'm getting an exception that really has me stumped. It's sporadic at best, it's only happened a handful of times. This particular time it happened when the user pressed 'Alt-S' to save the...
3
by: Christian McArdle | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.os.ms-windows.programmer.64bit This is a formal Request For Discussion (RFD) to create comp.os.ms-windows.programmer.64bit as an unmoderated...
5
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
1
by: Günther Rühmann | last post by:
Hi, I´m not sure if i´m right int this group... My problem: I made a vb .net application that reads from AD via System.Directoryservices.Directoryentry. The appliocation enumerates group...
7
by: lvpaul | last post by:
Hallo ! I am using IIS-Windows-Authentication in my intranet (web.config <authentication mode="Windows" /> <identity impersonate="true" /> How can I get the users (client) IP-Address ? I...
5
by: david | last post by:
I have developed my web service with a domain name of my computer name and wwwroot directory. I also developed a client of windows form application. It works locally (i.e. in the same machine). ...
7
by: Tyler Foreman | last post by:
Hello, I have a strange problem that occurs every so often in my application. It usually takes place when I hide one form and activate another. What happens is I get the following exception:...
1
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm...
0
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to do the following: - Select remote server -...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.