Click here to Skip to main content
15,908,673 members
Home / Discussions / C#
   

C#

 
AnswerRe: Poor thumbnail quality when using listview [modified] Pin
Luc Pattyn26-Feb-10 12:20
sitebuilderLuc Pattyn26-Feb-10 12:20 
Untested (see also my next message):

// input:  Bitmap bm1, size w1*h1
// output: Bitmap bm2, size w2*h2
public Bitmap ResizeImageKeepingAspectRatio(Bitmap bm1, int w2, int h2, Brush backColor) {
    int w1=bm1.Width;
    int h1=bm1.Height;
    Bitmap bm2=new Bitmap(w2, h2);
    Graphics g=Graphics.FromImage(bm2);
    g.FillRectangle(backColor, 0, 0, w2, h2);
    int x2=0;
    int y2=0;
    float scale=1;
    if (w1*h2>w2*h1) {// w2 is the limiting factor
       y2=h2-h1*w2/w1);
       scale=w2/(float)w1;
    } else {          // h2 is the limiting factor
       x2=w2-w1*h2/h1);
       scale=h2/(float)h1;
    }
    g.ScaleTransform(scale, scale);
    g.TranslateTransform(x2/2, y2/2);
    g.DrawImage(bm1, 0, 0);
    g.Dispose();
    return bm2;
}


You need to test this; I suggest you give it a 100*100 and convert it to first a 40*50, and then a 50*40.

Smile | :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]

I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
All Toronto weekends should be extremely wet until we get it automated in regular forums, not just QA.

modified on Friday, February 26, 2010 6:54 PM

GeneralRe: Poor thumbnail quality when using listview Pin
Eagle3227-Feb-10 0:24
Eagle3227-Feb-10 0:24 
GeneralRe: Poor thumbnail quality when using listview Pin
Luc Pattyn27-Feb-10 0:37
sitebuilderLuc Pattyn27-Feb-10 0:37 
GeneralRe: Poor thumbnail quality when using listview Pin
Eagle3227-Feb-10 6:44
Eagle3227-Feb-10 6:44 
GeneralRe: Poor thumbnail quality when using listview Pin
Luc Pattyn27-Feb-10 7:40
sitebuilderLuc Pattyn27-Feb-10 7:40 
GeneralRe: Poor thumbnail quality when using listview Pin
Eagle3227-Feb-10 7:59
Eagle3227-Feb-10 7:59 
GeneralRe: Poor thumbnail quality when using listview Pin
Luc Pattyn27-Feb-10 8:14
sitebuilderLuc Pattyn27-Feb-10 8:14 
GeneralRe: Poor thumbnail quality when using listview Pin
Eagle325-Mar-10 10:08
Eagle325-Mar-10 10:08 
AnswerRe: Poor thumbnail quality when using listview Pin
Luc Pattyn26-Feb-10 12:53
sitebuilderLuc Pattyn26-Feb-10 12:53 
Questionhow to create a cookie with C# ??? Pin
andyxfun26-Feb-10 8:37
andyxfun26-Feb-10 8:37 
AnswerRe: how to create a cookie with C# ??? Pin
Saksida Bojan26-Feb-10 8:56
Saksida Bojan26-Feb-10 8:56 
Questionvoice chat in windows mobile 6 Pin
Rodinho26-Feb-10 7:53
Rodinho26-Feb-10 7:53 
AnswerRe: voice chat in windows mobile 6 Pin
Dr.Walt Fair, PE26-Feb-10 8:46
professionalDr.Walt Fair, PE26-Feb-10 8:46 
GeneralRe: voice chat in windows mobile 6 Pin
Wes Aday26-Feb-10 9:03
professionalWes Aday26-Feb-10 9:03 
AnswerRe: voice chat in windows mobile 6 Pin
rioshzhao23-Sep-10 20:02
rioshzhao23-Sep-10 20:02 
QuestionCreate and remove controls dynamically ?????? Pin
Pawan Kiran26-Feb-10 7:29
Pawan Kiran26-Feb-10 7:29 
AnswerRe: Create and remove controls dynamically ?????? Pin
PIEBALDconsult26-Feb-10 7:36
mvePIEBALDconsult26-Feb-10 7:36 
AnswerRe: Create and remove controls dynamically ?????? Pin
kevinnicol26-Feb-10 7:36
kevinnicol26-Feb-10 7:36 
AnswerRe: Create and remove controls dynamically ?????? Pin
dan!sh 26-Feb-10 7:53
professional dan!sh 26-Feb-10 7:53 
Questiontext to excell Pin
michaelgr126-Feb-10 7:20
michaelgr126-Feb-10 7:20 
AnswerRe: text to excell Pin
dan!sh 26-Feb-10 7:26
professional dan!sh 26-Feb-10 7:26 
GeneralRe: text to excell Pin
michaelgr126-Feb-10 7:27
michaelgr126-Feb-10 7:27 
GeneralRe: text to excell Pin
dan!sh 26-Feb-10 7:35
professional dan!sh 26-Feb-10 7:35 
GeneralRe: text to excell Pin
michaelgr126-Feb-10 7:42
michaelgr126-Feb-10 7:42 
QuestionC# TableLayoutPanel MouseMove Too Much CPU Pin
ikurtz26-Feb-10 4:28
ikurtz26-Feb-10 4:28 

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.