473,396 Members | 2,052 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,396 software developers and data experts.

DrawImage does not expand bitmap correctly

1
I've created a BitMap 1 pixel wide & 256 pixel height
when i try to draw this bitmap as 2 pixels wide using:

public void DrawImage(Image image,RectangleF rect)

The bitmap is not drawn correctly. There are white
slim stripes in bitween each bitmap column.
see the simple code below:

Expand|Select|Wrap|Line Numbers
  1.    private void Form1_Paint(object sender, 
  2.                                  PaintEventArgs e)
  3.         {
  4.             Graphics gr = e.Graphics;
  5.  
  6.             Bitmap bitmap = new Bitmap(1, 256);
  7.             for (int y = 0; y < 256; y++)
  8.             {
  9.                 bitmap.SetPixel(0, y, Color.Red);
  10.             }
  11.  
  12.             RectangleF rectf = new RectangleF();
  13.  
  14.             for (int x = 0; x < 500; x++)
  15.             {
  16.                 float factor = 2;
  17.                 rectf.X = x*factor;
  18.                 rectf.Y = 0;
  19.                 rectf.Width = fact;
  20.                 rectf.Height = 500;
  21. // should draw bitmap as 2 pixels wide 
  22. // but draws it with white slim stripes in between
  23.                 gr.DrawImage(bitmap, rectf);
  24.             }           
  25.         }
Jul 19 '11 #1
2 2548
Rabbit
12,516 Expert Mod 8TB
Shouldn't the rectf.Width be factor? You put fact.
Jul 19 '11 #2
GaryTexmo
1,501 Expert 1GB
I took a look at this and yea, it's definitely funny. I did a bit of digging and I think it might have something to do with the InterpolationMode property on the Graphics object. Setting it to NearestNeighbor seemed to remove the smoothing, but it also appeared to cut the scaling in half (width wise) sometimes plus or minus one pixel. It was actually quite odd.

Maybe try playing around with that setting but another thing I stumbled across was the idea of using transforms. There should be one for scaling that might help you out. I've never actually used them (except a brief and failed experiment with rotations) but it's an avenue of exploration.
Jul 19 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Alexander Scheurer | last post by:
Hello, my problem is as following, I got a table like this: <table class=main> <tr> <td class=t11></td> <td class=t12></td> </tr> <tr>
1
by: James Dean | last post by:
I want to scale my bitmap. I use interpolation mode(Bicubic) and scaletransform of the graphics class. Does this automatically ensure the best quality when i scale my image. Do i need to do...
2
by: RalphTheExpert | last post by:
This thread is a continuation of a thread with the Subject "Unhandled exception - Different under debugger and non-debugger". (http://www.dotnetnewsgroups.com/newsgroupthread.asp?ID=186902) ...
3
by: john | last post by:
Hi to All To demonstrate: public class MyBaseGenericClass<T> { } public class MyGenericClass1<T: MyBaseGenericClass<T> {
0
by: cmbardon | last post by:
I'm trying to create a form with some rounded controls, and I'm having some problems with the rounding not working correctly. I've tried a couple of different methods for creating the graphics...
2
by: Peter Oliphant | last post by:
The Image class allows loading a bitmap from a graphic file. So far I've gotten it to work with JPG and BMP files. What other graphic file formats are supported in this way? Is this fixed based...
1
by: =?Utf-8?B?S2F0aHll?= | last post by:
I am trying to merge multiple .chm files and cannot get the child TOC to merge correctly. I followed the instructions in the HHW Help on "Creating links from one contents file to another", but when...
5
by: =?Utf-8?B?Y3lydXM=?= | last post by:
Hi everybody, I have created a simple web form which contains a repeater. every item of the repeater has a button to delete the tiem. my web form uses Resource files to globalizing the form...
2
by: brixton | last post by:
Hello, I have an "accordion menu" where I want the structure to be like this for a menu item with "children" who are supposed to drop down when an "expand image" is clicked: <li> <span>some...
3
by: Steve Pettis | last post by:
I am testing a web page under development using IIS. The localhost URL is pointed to the folder on my hard drive containing the code in question. The index.html file defines a frameset containing 3...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.