简体   繁体   中英

c# width increased bitmap turns transparent

i tried to draw a headerCell.

original picture looks like this (increased):

增加

I tried to stretch the images width:

 Bitmap bmp = new Bitmap(3000, 1000);
 Graphics graph = Graphics.FromImage(bmp);
 Image headerMain = Image.FromFile(imagePfad + "header_main.jpg");
 graph.DrawImage(headerMain, X, Y, 300, headerMain.Height);

 Graphics g = CreateGraphics();
 g.DrawImage(bmp, 0, 0);

But then it turns into transparent like this:

headerPic

what am i doing wrong?

At such extreme magnifications, the work done by the interpolation filter becomes highly visible. You'll want to de-tune it to nearest-neighbor, pixel offset mode matters too:

graph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
graph.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM