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.Dra wImage( 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.FromIm age(bitmap);
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transf orm = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLi ne(myPen, 90, 0, 100, 100);
graphics.Dispos e();
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 5 2561
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.Dra wImage( 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.FromIm age(bitmap);
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transf orm = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLi ne(myPen, 90, 0, 100, 100);
graphics.Dispos e();
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
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.Dra wImage( 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.FromIm age(bitmap);
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transf orm = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLi ne(myPen, 90, 0, 100, 100);
graphics.Dispos e();
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
You'd have to also draw the bitmap.
Something like (aircode):
if (bitmap == null) return;
Bitmap newBitmap = new bitmap(bitmap.W idth, bitmap.Height);
using(Graphics graphics = Graphics.FromIm age(newBitmap))
{
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transf orm = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLi ne(myPen, 90, 0, 100, 100);
graphics.DrawIm age(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.FromI mage) 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.Dra wImage( 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.FromIm age(bitmap);
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transf orm = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLi ne(myPen, 90, 0, 100, 100);
graphics.Dispos e();
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
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.W idth, bitmap.Height);
using(Graphics graphics = Graphics.FromIm age(newBitmap))
{
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transf orm = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLi ne(myPen, 90, 0, 100, 100);
graphics.DrawIm age(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.FromI mage) 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.Dra wImage( 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.FromIm age(bitmap);
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transf orm = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLi ne(myPen, 90, 0, 100, 100);
graphics.Dispos e();
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
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.W idth, bitmap.Height);
using(Graphics graphics = Graphics.FromIm age(newBitmap))
{
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transf orm = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLi ne(myPen, 90, 0, 100, 100);
graphics.DrawIm age(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.FromI mage) 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.Dra wImage( 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.FromIm age(bitmap);
Matrix X = new Matrix();
X.Translate(10, 0);
graphics.Transf orm = X;
Pen myPen = new Pen(Color.Red, 1);
graphics.DrawLi ne(myPen, 90, 0, 100, 100);
graphics.Dispos e();
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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)
{
Graphics g;
g = pictureBox1.CreateGraphics();
g.FillRectangle(Brushes.White,0,0,160,160);
|
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 froggraphic As Graphics = Graphics.FromImage(frogbitmap)
froggraphic.RotateTransform(90)
frogbitmap.Save(Server.MapPath("images/frog2.gif"),...
|
by: Fir5tSight |
last post by:
Hi All,
I used the following code in C#:
using System.Drawing;
//blah blah blah
Bitmap bmp = new Bitmap();
|
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 doing something
was really inefficient and could reduce 10 lines of code with 2, etc.
For reading, I am using a TcpClient and I call
...
|
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 below:
chartGenerator.vb class:
Imports System.Drawing.Imaging
Public Class chartGenerator
Private myImage As Bitmap
| |
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 FromImage call will fail for indexed bitmaps.
|
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.
The issue Im having is that I cant find any tutorials on how to do the
following:
I have three graphics the Right End Cap the center (which I...
|
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 that point to
the colors in a Palette of the display driver.
So if I get a bitmap via CF_BITMAP I need to also get a Palette off the
clipboard and...
|
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 located at (x,y)=(10,20)
(upper-left hand corner) and is 50x50 in size of the source Bitmap. A
sub-Bitmap if you will, sort of the equivalent to...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |