473,387 Members | 1,520 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,387 software developers and data experts.

C# how using graphics properly

Hello!

I'm writing a graphic program in C# (at first time).
The pixel of the picture stored in array of varible.
Expand|Select|Wrap|Line Numbers
  1.     public partial class Form1 : Form
  2.     {
  3.         public Bitmap scrBitmap = new Bitmap(1280, 800, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
  4.         public Graphics ScrGraph; 
  5.  
(ScrGraph is a Graphics varible for graphics, scrBitmap
is for the picture.)

I tried using for drawing picture, but nothig happen.
Expand|Select|Wrap|Line Numbers
  1. ScrGraph.DrawImage(scrBitmap, 0, 0,1280,800);
  2.  
I starting to debug the program, but stop that line. The error is "NullReferenceExeption was unhandled."

How use the graphics and the drawimage function properly to update the picture?
Jun 7 '11 #1
1 1881
GaryTexmo
1,501 Expert 1GB
Your graphics object needs to be set to something. When you create a new variable it's typically initialized to null. Where are you calling the DrawImage method on your graphics object?

If it's in the OnPaint method for a form, there should be a PaintEventArgs parameter in the parameter list for that method. There is a graphics object inside that event args object. If you're just doing it somewhere on the form, initialize ScrGraph in your constructor with this.CreateGraphics().

You mentioned you were new, so if this confuses you please post your complete source so I can see what you're doing.

Thanks!
Jun 7 '11 #2

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

Similar topics

8
by: ComputerSmith | last post by:
Hi all. I have programmed VB6 apps before, ones that use dropdown listboxes, text boxes, etc... normal stuff. I was asked by a friend to write a "simple" app that I am unsure how to proceed...
5
by: Vin | last post by:
Hi, I am using the following code to draw whatever the user draws using x,y. // draws lines directly on a winform. CreateGraphics().DrawLine(APen, x, y, OldX, OldY); Now how do I save the...
2
by: Coralin Feierbach | last post by:
I created a Windows Form Project using VS.net. I'm trying to draw a line between two points. (Plotting a graph, dynamically) This is the code I have so far: What do I have to do to actually see...
6
by: johannblake | last post by:
I am wondering whether it is easy to setup a coordinate system for drawing (using GDI+) that uses meters (or any custom scaling for that matter). Currently, I need to convert from pixels to meters...
2
by: rushikesh.joshi | last post by:
Hi All, I want to create a webcontrol which will generate a bar (bar chart). I have done some graphics code in my ASPX page and it's working fine, but how do i create a Custom Control or User...
1
by: rushikesh.joshi | last post by:
Hi All, I want some charting functionality in my ASP.NET application. I want to show a multiple bar on my web page. It's based on down time of different servers. like server1: down betn 4 AM...
0
by: biltz | last post by:
i made a prog by using graphics.h....but when i run it it give \\bgi error actually i used settextstyle but its giveing eroor..do any body help me out wut 2 do?
2
by: koolest1 | last post by:
Here's a code for scan conversion of a line using DDA algorithm.... but i guess there's some problem in the sense that not every kind of line is getting plotted properly (at least that's what i...
2
by: Hvid Hat | last post by:
Hi Is it somehow possible to call Graphics.DrawLine with List<Point>? Does it only take Point arrays? If so, how can I (easily) convert my List<Point> to a Point array?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.