|
Alexander,
Once agin thanx! I am now at home and will check in the morning (8:00 am CST). I really appreciate your effort. I have been trying to google the problem all day! I am only checking now at home because I think I have some kind of obcessive compulsive disorder when it comes to troubleshooting!
I'll keep you in the loop tomorrow!
Thanx again,
Tom
|
|
|
|
|
Alexander,
Tried setting the trans key to lime green with no luck. It did help a little because now it only does the black flicker when the opacity is initially changed. It also appears more resources are being used (slower). I'm going to continue the search.
Thanx,
Tom
|
|
|
|
|
Tom,
Seeing what Alexander posted, I decided I might as well try this for myself. My system only shows the black part for a small fraction of a second. It's barely noticeable, but it's still there. Once it's done, then I don't see it again. So, I decided I'd cheat a bit. Here's what I did and this seems to work for me. I put this in my form's constructor:
public Form1()
{
InitializeComponent();
this.Opacity = 0.50D;
this.Opacity = 1.00D;
}
AFAIK, the window is not shown when it's constructed. But the opacity still takes effect. Can you try this and tell us if it fixes your problem?
Logifusion[^]
|
|
|
|
|
Dustin,
Thanks again for helping me fight the good fight! I had already tried this method (tried it again). All this does is move the flicker problem to when the form is first created. It does eliminate the black flicker when the control is used but still the ugly black flicker even when the form is created is not going to work.
Thanks Anyway!
I'm trying to find an article I saw a few days ago which had a long drawn out solution. At the time I thought the guy was crazy to go through that much work to get rid of the black flicker. He must have went through this long search for the "easy" answer. The premise of his solution involved setting and painting everything programatically. BACK TO THE SEARCH!!
I WILL PREVAIL!!!
|
|
|
|
|
Humor me for a second and try:
this.WindowState = FormWindowState.Minimized;
this.Opacity = 0.50D;
this.Opacity = 1.00D;
this.WindowState = FormWindowState.Normal;
Logifusion[^]
|
|
|
|
|
Dustin,
I tried a couple of things along these lines as well. I didn't try Minimized but I did try hiding and showing the form and I still got the initial black flicker. I think it must have something to do with the way layered windows work. Aside from complete custom paint handling, etc, I can't think of anything else currently.
Sincerely,
Alexander Wiseman
|
|
|
|
|
Then, I guess the solution for Tom is: Get a faster computer!
Really, when I change the opacity of the form in the constructor I never see a black flicker. So, in Tom's case it might work fine on some computers, but not on others.
Oh! Another thing we could try is a splash screen. Put the splash screen up in front of the app window when the flickering is going on so that the user doesn't see it.
Logifusion[^]
|
|
|
|
|
I just tried that!
It didn't work. It helped a little bit, but still there was a black flicker when the form was hidden. I made the splash screen a child form of the main form, so maybe if you had the splash screen be a top-level form something different would happen, but I don't think so.
Sincerely,
Alexander Wiseman
|
|
|
|
|
Dustin,
No humor needed! You're helping me and I'm willing to try anything at this point. It didn't work. I like the idea though. I'm trying to figure a way to delay displaying the form for a second after ShowDialog() is called.
Thanx again for helping!
I WILL PREVAIL!!
TIS MEERLY A FLESH WOUND!!
Tom
|
|
|
|
|
Well, while we're on the subject of crazy ideas. How about this:
Your form comes up initially and it's the one you want to change the opacity on. We'll call it Form A. Now create another form that is an exact duplicate of Form A (same position and everything) and call it Form B. Form B comes up in front of Form A. Change the opacity of form A and set it back to whatever default you want. Then get rid of Form B. If it goes fast, the user won't know a thing!
I think I'm having too much fun with this. Maybe I should get back to work.
Logifusion[^]
|
|
|
|
|
Don't know if you've already tried this but here's another idea:
this.SetDesktopLocation(this.Location.X + 10000, this.Location.Y);
this.Opacity = 0.50D;
this.Opacity = 1.00D;
this.SetDesktopLocation(this.Location.X - 10000, this.Location.Y);
I figure if it's going to show the black flicker, it could do it off screen.
Logifusion[^]
|
|
|
|
|
Hi,
With images from files or from a database I don't have problems but when I work with images created starting from an object "Graphics" the images don't survive. How can I save this Bitmap?, I tried with:
...
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( widthBmp, heightBmp );
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage( bmp );
...
MemoryStream stream = new MemoryStream();
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] buffer = new Byte[stream.Length];
stream.Position = 0;
stream.Read(buffer, 0, (int) buffer.Length);
...
buffer = null;
stream.Close();
but the image always is black...
Thanks a lot
Abel Castillo
|
|
|
|
|
Hey there,
I think there are a few problems in your code but I'm not 100% sure. First of all, your sample here doesn't really draw anyhting on the bitmap so - it should be black. Second of all, if you want to save the bitmap you will most likely need a FileStream, not a MemoryStream. The MemoryStream is just an in-memory stream. It will not be persisted anywhere.
Maybe if you provide a bit more of your code here we'll be able to help out.
Cheers
----
www.digitalGetto.com
|
|
|
|
|
The image is drawn in another method ("DrawGraphics") but I didn't include it because it is very long
this it is a summary of the code:
public System.Drawing.Bitmap CreateBitmap( )
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( widthBmp, heightBmp );
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage( bmp );
DrawGraphics( g, new System.Drawing.Point( 0, 0 ) );
g.Dispose( );
return bmp;
}
System.Drawing.Bitmap bmp = CreateBitmap();
// make a memory stream to work with the image bytes
MemoryStream stream = new MemoryStream();
// put the image into the memory stream
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
// make byte array the same size as the image
byte[] buffer = new Byte[stream.Length];
// rewind the memory stream
stream.Position = 0;
// load the byte array with the image
stream.Read(buffer, 0, (int) buffer.Length);
then
save the image in sql database, but the array of bytes (variable buffer) has no images, it´s totally black...
Thank you for the answer
Abel Castillo
|
|
|
|
|
I'd say the problem is in the way you are creating the bitmap, and not how you save it into the MemoryStream. Josh is right, about not saving to a file but from your post I understand that it is not your intention to save to a file but rather to store the image bytes in a SQL database.
I think the problem is in the CreateBitmap() function. I suspect it has to do with the fact that you create a graphics context from a bitmap that is empty. Than you draw to the graphics object but then dispose of it before saving. I'm not sure if that is what's going on but before you try saving it, draw it on a canvas on the screen to make sure the bitmap is properly created by CreateBitmap()
----
www.digitalGetto.com
|
|
|
|
|
I agree with you, I have no problems to save the image to a SQL database and to show it in a PictureBox. But when I tried to save in a array of bytes ...
I'm working with the code of the excellent article Creating EAN-13 Barcodes with C#[^] by rainman_63. I generate the barcodes of several articles and I need to pass them to a database SQL, I have carried out several tests but up to now without success.
Ean13 ean13 = new Ean13();<br />
ean13.CountryCode = "84";<br />
ean13.ManufacturerCode = "862";<br />
ean13.ProductCode = "3274243";<br />
ean13.ChecksumDigit = "7";<br />
ean13.Scale = 1f;<br />
Bitmap bmp = ean13.CreateBitmap();<br />
<br />
MemoryStream stream = new MemoryStream();<br />
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);<br />
byte[] buffer = new Byte[stream.Length];<br />
stream.Position = 0;<br />
stream.Read(buffer, 0, (int) buffer.Length);
here save barcodes (buffer) in a SQL database
buffer = null;<br />
stream.Close();
Thanks a lot
Abel Castillo
-- modified at 5:16 Thursday 22nd June, 2006
|
|
|
|
|
|
I don't know what is not working in your application but here is code that I wrote to verify your concept and it all works. To me, the problem is in your CreateBitmap() function.
To test the following code, create a new C# Windows Apllication. Drag and Drop two picture boxes on your form. Then paste this code as your Form Load event handler:
<code language="c#">
private void Form1_Load(object sender, EventArgs e)
{
MemoryStream memStream = new MemoryStream();
byte[] myBytes;
using (Bitmap bmp = new Bitmap(50, 50))
using (Graphics grfx = Graphics.FromImage(bmp))
{
grfx.FillRectangle(Brushes.Red, new Rectangle(0, 0, 50, 50));
bmp.Save(memStream, System.Drawing.Imaging.ImageFormat.Bmp);
myBytes = new byte[memStream.Length];
memStream.Position = 0;
memStream.Read(myBytes, 0, (int)memStream.Length);
pictureBox1.Image = Image.FromStream(memStream);
pictureBox2.Image = Image.FromStream(new MemoryStream(myBytes));
}
}
</code>
*** Portion of the code above is taken from the post below[^]
----
www.digitalGetto.com
-- modified at 12:38 Thursday 22nd June, 2006
|
|
|
|
|
Hello mikanu,
This is the code:
public System.Drawing.Bitmap CreateBitmap( )
{
float tempWidth = ( this.Width * this.Scale ) * 100 ;
float tempHeight = ( this.Height * this.Scale ) * 100;
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( (int)tempWidth, (int)tempHeight );
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage( bmp );
this.DrawEan13Barcode( g, new System.Drawing.Point( 0, 0 ) );
g.Dispose( );
return bmp;
}
public void DrawEan13Barcode( System.Drawing.Graphics g, System.Drawing.Point pt )
{
float width = this.Width * this.Scale;
float height = this.Height * this.Scale;
float lineWidth = width / 113f;
System.Drawing.Drawing2D.GraphicsState gs = g.Save( );
g.PageUnit = System.Drawing.GraphicsUnit.Millimeter;
g.PageScale = 1;
System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush( System.Drawing.Color.Black );
float xPosition = 0;
System.Text.StringBuilder strbEAN13 = new System.Text.StringBuilder( );
System.Text.StringBuilder sbTemp = new System.Text.StringBuilder( );
float xStart = pt.X;
float yStart = pt.Y;
float xEnd = 0;
System.Drawing.Font font = new System.Drawing.Font( "Arial", this._fFontSize * this.Scale );
this.CalculateChecksumDigit( );
sbTemp.AppendFormat( "{0}{1}{2}{3}",
this.CountryCode,
this.ManufacturerCode,
this.ProductCode,
this.ChecksumDigit );
string sTemp = sbTemp.ToString( );
string sLeftPattern = "";
sLeftPattern = ConvertLeftPattern( sTemp.Substring( 0, 7 ) );
strbEAN13.AppendFormat( "{0}{1}{2}{3}{4}{1}{0}",
this._sQuiteZone, this._sLeadTail,
sLeftPattern,
this._sSeparator,
ConvertToDigitPatterns( sTemp.Substring( 7 ), this._aRight ) );
string sTempUPC = strbEAN13.ToString( );
float fTextHeight = g.MeasureString( sTempUPC, font ).Height;
for( int i = 0; i < strbEAN13.Length; i++ )
{
if( sTempUPC.Substring( i, 1 ) == "1" )
{
if( xStart == pt.X )
xStart = xPosition;
if( ( i > 12 && i < 55 ) || ( i > 57 && i < 101 ) )
g.FillRectangle( brush, xPosition, yStart, lineWidth, height - fTextHeight );
else
g.FillRectangle( brush, xPosition, yStart, lineWidth, height );
}
xPosition += lineWidth;
xEnd = xPosition;
}
xPosition = xStart - g.MeasureString( this.CountryCode.Substring( 0, 1 ), font ).Width;
float yPosition = yStart + ( height - fTextHeight );
g.DrawString( sTemp.Substring( 0, 1 ), font, brush, new System.Drawing.PointF( xPosition, yPosition ) );
xPosition += ( g.MeasureString( sTemp.Substring( 0, 1 ), font ).Width + 43 * lineWidth ) -
( g.MeasureString( sTemp.Substring( 1, 6 ), font ).Width );
g.DrawString( sTemp.Substring( 1, 6 ), font, brush, new System.Drawing.PointF( xPosition, yPosition ) );
xPosition += g.MeasureString( sTemp.Substring( 1, 6 ), font ).Width + ( 11 * lineWidth );
g.DrawString( sTemp.Substring( 7 ), font, brush, new System.Drawing.PointF( xPosition, yPosition ) );
g.Restore( gs );
}
the difference would be the code of the function DrawEan13Barcode, but I don't know why...
I have carried out many tests, but when I use the graph that returns this function I can show it in a PictureBox but never to save it successfully in a stream.
Excuses my insistence, thanks for your time
Abel Castillo
|
|
|
|
|
The only difference that I could think of it that you dispose of the Graphics object in the CreateBitmap function whereas I created the MemoryStream before disposing the Graphics object. Give that a try.. I don't have a lot of time on my hands right now to test, but I'd be intereseted to know if that fixes it.
Miky
----
www.digitalGetto.com
|
|
|
|
|
Thanks Miky,
I'm making other tests and contacting with other programmers, when I find the solution I publish it.
cheers Abel
Abel Castillo
|
|
|
|
|
This works for me:
private void button1_Click(object sender, System.EventArgs e)
{
using( Bitmap bmp = new Bitmap( 50, 50 ) )
using( Graphics grfx = Graphics.FromImage( bmp ) )
{
grfx.FillRectangle( Brushes.Red, new Rectangle(0,0,50,50) );
using( FileStream stream = new FileStream( @"C:\test.jpg", FileMode.Create ) )
{
bmp.Save( stream, System.Drawing.Imaging.ImageFormat.Jpeg );
}
}
}
I think the difference between our code is that I am saving to a FileStream, but you are saving to a MemoryStream. Your stream does not send the image to a file.
Josh
|
|
|
|
|
hello all
i'm new to the world of directX and directShow.
i need to draw shapes on video.
does anyone know how to do that? where should i begin?
thanks
eyal
|
|
|
|
|
I would think that you could get the device context for whatever window the video is playing in and draw on there as normal - however, don't quote me on this.
My Music | My Pics | My Articles
BlackDice
|
|
|
|
|
Last painter wins... and around the back stretch it's DirectX by a nose!
|
|
|
|
|