473,497 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

building up a bitmap

I have a bitmap of 100X100. On the load, the bitmap is created by a function
(createimage()). On my OnPaint, I draw the image back to the screen
(e.Graphics.DrawImage( bitmap, destrect)).

Now, I want to add a button. When user click on it, I want the bitmap shift
to the left by 10% and fill the new area with new information requested.
Here is the code I have in the button handler:
if (bitmap == null) return;
Graphics graphics = Graphics.FromImage(bitmap);
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transform = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLine(myPen, 90, 0, 100, 100);
graphics.Dispose();
Invalidate();
The problem here is that I don't see any translation of my bitmap. Can
someone point me where the problem is?

Thanks in advance,
Anthony
Oct 22 '07 #1
5 2556
You're only drawing a line, only the line will be transformed.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"ATT" wrote:
I have a bitmap of 100X100. On the load, the bitmap is created by a function
(createimage()). On my OnPaint, I draw the image back to the screen
(e.Graphics.DrawImage( bitmap, destrect)).

Now, I want to add a button. When user click on it, I want the bitmap shift
to the left by 10% and fill the new area with new information requested.
Here is the code I have in the button handler:
if (bitmap == null) return;
Graphics graphics = Graphics.FromImage(bitmap);
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transform = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLine(myPen, 90, 0, 100, 100);
graphics.Dispose();
Invalidate();
The problem here is that I don't see any translation of my bitmap. Can
someone point me where the problem is?

Thanks in advance,
Anthony
Oct 22 '07 #2
Oh! How do I transform the whole bitmap then ? If using Matrix cannot do
it, can you point me how I can shift my bitmap?

"Peter Ritchie [C# MVP]" wrote:
You're only drawing a line, only the line will be transformed.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"ATT" wrote:
I have a bitmap of 100X100. On the load, the bitmap is created by a function
(createimage()). On my OnPaint, I draw the image back to the screen
(e.Graphics.DrawImage( bitmap, destrect)).

Now, I want to add a button. When user click on it, I want the bitmap shift
to the left by 10% and fill the new area with new information requested.
Here is the code I have in the button handler:
if (bitmap == null) return;
Graphics graphics = Graphics.FromImage(bitmap);
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transform = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLine(myPen, 90, 0, 100, 100);
graphics.Dispose();
Invalidate();
The problem here is that I don't see any translation of my bitmap. Can
someone point me where the problem is?

Thanks in advance,
Anthony
Oct 22 '07 #3
You'd have to also draw the bitmap.

Something like (aircode):
if (bitmap == null) return;
Bitmap newBitmap = new bitmap(bitmap.Width, bitmap.Height);
using(Graphics graphics = Graphics.FromImage(newBitmap))
{
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transform = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLine(myPen, 90, 0, 100, 100);
graphics.DrawImage(bitmap, 0,0);
}
bitmap = newBitmap;
Invalidate();

If you using a PictureBox, you'll have to re-assign the bitmap property,
unless you use bitmap as the destination (Graphics.FromImage) and load the
bitmap you're drawing into a new bitmap object.
--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"ATT" wrote:
Oh! How do I transform the whole bitmap then ? If using Matrix cannot do
it, can you point me how I can shift my bitmap?

"Peter Ritchie [C# MVP]" wrote:
You're only drawing a line, only the line will be transformed.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"ATT" wrote:
I have a bitmap of 100X100. On the load, the bitmap is created by a function
(createimage()). On my OnPaint, I draw the image back to the screen
(e.Graphics.DrawImage( bitmap, destrect)).
>
Now, I want to add a button. When user click on it, I want the bitmap shift
to the left by 10% and fill the new area with new information requested.
Here is the code I have in the button handler:
if (bitmap == null) return;
Graphics graphics = Graphics.FromImage(bitmap);
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transform = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLine(myPen, 90, 0, 100, 100);
graphics.Dispose();
Invalidate();
The problem here is that I don't see any translation of my bitmap. Can
someone point me where the problem is?
>
Thanks in advance,
Anthony
Oct 22 '07 #4
that works! Thank you, Peter.

Things considered. I don't need to use the Matrix since I am doing a simple
translation. I can have the save effect using the drawImage with its
parameters. I thought I don't have to build a second bitmap which is a
resource waste.

Anthony.

"Peter Ritchie [C# MVP]" wrote:
You'd have to also draw the bitmap.

Something like (aircode):
if (bitmap == null) return;
Bitmap newBitmap = new bitmap(bitmap.Width, bitmap.Height);
using(Graphics graphics = Graphics.FromImage(newBitmap))
{
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transform = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLine(myPen, 90, 0, 100, 100);
graphics.DrawImage(bitmap, 0,0);
}
bitmap = newBitmap;
Invalidate();

If you using a PictureBox, you'll have to re-assign the bitmap property,
unless you use bitmap as the destination (Graphics.FromImage) and load the
bitmap you're drawing into a new bitmap object.
--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"ATT" wrote:
Oh! How do I transform the whole bitmap then ? If using Matrix cannot do
it, can you point me how I can shift my bitmap?

"Peter Ritchie [C# MVP]" wrote:
You're only drawing a line, only the line will be transformed.
>
--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
>
>
"ATT" wrote:
>
I have a bitmap of 100X100. On the load, the bitmap is created by a function
(createimage()). On my OnPaint, I draw the image back to the screen
(e.Graphics.DrawImage( bitmap, destrect)).

Now, I want to add a button. When user click on it, I want the bitmap shift
to the left by 10% and fill the new area with new information requested.
Here is the code I have in the button handler:
if (bitmap == null) return;
Graphics graphics = Graphics.FromImage(bitmap);
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transform = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLine(myPen, 90, 0, 100, 100);
graphics.Dispose();
Invalidate();
The problem here is that I don't see any translation of my bitmap. Can
someone point me where the problem is?

Thanks in advance,
Anthony
Oct 22 '07 #5
Yes, you have many better options. I tried to keep the sample as close to
your orignal as possible in case it was more complex to change other code...

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"ATT" wrote:
that works! Thank you, Peter.

Things considered. I don't need to use the Matrix since I am doing a simple
translation. I can have the save effect using the drawImage with its
parameters. I thought I don't have to build a second bitmap which is a
resource waste.

Anthony.

"Peter Ritchie [C# MVP]" wrote:
You'd have to also draw the bitmap.

Something like (aircode):
if (bitmap == null) return;
Bitmap newBitmap = new bitmap(bitmap.Width, bitmap.Height);
using(Graphics graphics = Graphics.FromImage(newBitmap))
{
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transform = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLine(myPen, 90, 0, 100, 100);
graphics.DrawImage(bitmap, 0,0);
}
bitmap = newBitmap;
Invalidate();

If you using a PictureBox, you'll have to re-assign the bitmap property,
unless you use bitmap as the destination (Graphics.FromImage) and load the
bitmap you're drawing into a new bitmap object.
--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"ATT" wrote:
Oh! How do I transform the whole bitmap then ? If using Matrix cannot do
it, can you point me how I can shift my bitmap?
>
"Peter Ritchie [C# MVP]" wrote:
>
You're only drawing a line, only the line will be transformed.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#


"ATT" wrote:

I have a bitmap of 100X100. On the load, the bitmap is created by a function
(createimage()). On my OnPaint, I draw the image back to the screen
(e.Graphics.DrawImage( bitmap, destrect)).
>
Now, I want to add a button. When user click on it, I want the bitmap shift
to the left by 10% and fill the new area with new information requested.
Here is the code I have in the button handler:
if (bitmap == null) return;
Graphics graphics = Graphics.FromImage(bitmap);
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transform = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLine(myPen, 90, 0, 100, 100);
graphics.Dispose();
Invalidate();
The problem here is that I don't see any translation of my bitmap. Can
someone point me where the problem is?
>
Thanks in advance,
Anthony
Oct 22 '07 #6

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

Similar topics

6
61719
by: charsh | last post by:
Hi, I using the code below to draw a text in a pictureBox1. //Start--------------------------------------------------------------- private void button1_Click(object sender, System.EventArgs e)...
8
3294
by: Nathan Sokalski | last post by:
I am trying to write code to rotate a graphic that I have. Here is the code I am currently using: Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("images/frog.gif"))) Dim...
7
8216
by: Fir5tSight | last post by:
Hi All, I used the following code in C#: using System.Drawing; //blah blah blah Bitmap bmp = new Bitmap();
14
11857
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
0
2846
by: benfly08 | last post by:
Hi, guys. I have a program to draw bar/pie chart based on the data i hard coded in it. However, my image comes with "BLACK" background color. I don't know how to fix this. The code snippet is...
8
4288
by: Joergen Bech | last post by:
Suppose I have Dim bm As New Bitmap(16, 16,Imaging.PixelFormat.Format8bppIndexed) I cannot use Dim g As Graphics = Graphics.FromImage(bmdest) Dim hdc As IntPtr = g.GetHdc() as the...
0
1104
by: RSH | last post by:
Hi, I am building a Win Forms application that I would like to feed a function a collection of strings (button text) that the program will go through and generate and save the generated buttons....
6
2432
by: \Frank\ | last post by:
I trying to learn what a Bitmap is. Not a Managed Bitmap Object but one that, for example, comes from the clipboard with CF_BITMAP. I'm guessing that a CompatableBitmap is an array of indices...
2
2579
by: Peter Oliphant | last post by:
I want to create a new Bitmap which is a portion of an existing Bitmap. For example, if I have a Bitmap that is 100x100 in size I might want to create a new Bitmap that is equivalent to the one...
0
7120
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
6991
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
7160
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
7196
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...
1
6878
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
7373
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
4583
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.