Click here to Skip to main content
15,908,842 members
Home / Discussions / Graphics
   

Graphics

 
GeneralRe: change forms caption and border Pin
prasad_som14-Mar-07 23:46
prasad_som14-Mar-07 23:46 
QuestionJPEG Extended ? Pin
Christian Graus10-Mar-07 7:12
protectorChristian Graus10-Mar-07 7:12 
QuestionRe: JPEG Extended ? Pin
Mark Salsbery10-Mar-07 7:16
Mark Salsbery10-Mar-07 7:16 
AnswerRe: JPEG Extended ? Pin
Christian Graus10-Mar-07 7:21
protectorChristian Graus10-Mar-07 7:21 
AnswerRe: JPEG Extended ? Pin
Christian Graus10-Mar-07 7:28
protectorChristian Graus10-Mar-07 7:28 
AnswerRe: JPEG Extended ? Pin
User 171649212-Mar-07 14:53
professionalUser 171649212-Mar-07 14:53 
GeneralRe: JPEG Extended ? Pin
Christian Graus27-Mar-07 2:51
protectorChristian Graus27-Mar-07 2:51 
QuestionDrawing in background thread Pin
Aaron Schaefer9-Mar-07 4:50
Aaron Schaefer9-Mar-07 4:50 
Help! I'm working on a control that does a fair amount of work to render itself. I've got it set up where it basically does all of its drawing to a bitmap that it holds on to, and then in the Paint method just copies the data from the bitmap to the client area, depdning on how much of it is currently visible, zoom factor, etc. Certain operations by the user can cause this bitmap to need to be redrawn. This is a time consuming operation (might take 5-10 seconds), and I'd like to update the bitmap in a worker thread, so that the app doesn't freeze while its doing its rendering. Anyone know how to go about this?

I created a BackgroundWorker, as follows:

I initialize the worker here:

worker = new BackgroundWorker();
worker.WorkerReportsProgress = false;
worker.WorkerSupportsCancellation = false;
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
worker.DoWork += new DoWorkEventHandler(worker_DoWork);

Then, if my bitmap needs to be redrawn, I start it here:


worker.RunWorkerAsync();

void worker_DoWork(object sender, DoWorkEventArgs e)
{
// Create a new bitmap for the log
int width = (int)Math.Round(Width * fDPIX);
int height = LogHeightPixels;

bmp = new Bitmap(width, height);
DrawLogToBitmap(bmp);
e.Result = bmp;
}

void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Bitmap bmpNew = (Bitmap)e.Result;
if (bmp != null)
{
bmp.Dispose();
bmp = null;
}
bmp = bmpNew;
}


In the DoWork handler, I create a new bitmap, do the drawing, and then assign the bitmap to the Result parameter in the RunWorkerCompletedEventArgs. It looks fine here, but then I get back to the main thread (in the RunWorkerCompleted) and the bitmap looks like garbage there.

Any ideas what I might be doing wrong?

Thanks In Advance,

Aaron


AnswerRe: Drawing in background thread Pin
Mark Salsbery9-Mar-07 6:32
Mark Salsbery9-Mar-07 6:32 
GeneralRe: Drawing in background thread Pin
Aaron Schaefer9-Mar-07 7:27
Aaron Schaefer9-Mar-07 7:27 
QuestionRe: Drawing in background thread Pin
Mark Salsbery9-Mar-07 12:11
Mark Salsbery9-Mar-07 12:11 
AnswerRe: Drawing in background thread Pin
Aaron Schaefer9-Mar-07 15:36
Aaron Schaefer9-Mar-07 15:36 
GeneralRe: Drawing in background thread Pin
Mark Salsbery10-Mar-07 6:38
Mark Salsbery10-Mar-07 6:38 
GeneralRe: Drawing in background thread Pin
vineas22-Mar-07 20:19
vineas22-Mar-07 20:19 
QuestionExtracting specific image from tiff... Pin
PandemoniumPasha8-Mar-07 22:27
PandemoniumPasha8-Mar-07 22:27 
AnswerRe: Extracting specific image from tiff... Pin
PandemoniumPasha9-Mar-07 0:44
PandemoniumPasha9-Mar-07 0:44 
GeneralRe: Extracting specific image from tiff... Pin
Mogtabam10-Mar-07 21:07
Mogtabam10-Mar-07 21:07 
GeneralRe: Extracting specific image from tiff... Pin
Mark Salsbery11-Mar-07 9:16
Mark Salsbery11-Mar-07 9:16 
QuestionManaged DirectX DeviceResizing Pin
Dmitri Nеstеruk6-Mar-07 4:07
Dmitri Nеstеruk6-Mar-07 4:07 
QuestionMax Rectangles In Any Shape Pin
zbaum002-Mar-07 11:49
zbaum002-Mar-07 11:49 
AnswerRe: Max Rectangles In Any Shape Pin
John R. Shaw3-Mar-07 0:36
John R. Shaw3-Mar-07 0:36 
GeneralRe: Max Rectangles In Any Shape Pin
zbaum004-Mar-07 10:38
zbaum004-Mar-07 10:38 
GeneralRe: Max Rectangles In Any Shape Pin
John R. Shaw9-Mar-07 8:35
John R. Shaw9-Mar-07 8:35 
AnswerRe: Max Rectangles In Any Shape Pin
Shog99-Mar-07 11:21
sitebuilderShog99-Mar-07 11:21 
QuestionHow to Connect DV Video Encoder to FileWriter Pin
Brooks Harris2-Mar-07 11:18
Brooks Harris2-Mar-07 11:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.