HighTechTalks DotNet Forums  

why ,save 1.bmp is black ???

Dotnet Framework (Drawing) microsoft.public.dotnet.framework.drawing


Discuss why ,save 1.bmp is black ??? in the Dotnet Framework (Drawing) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
etjon
 
Posts: n/a

Default why ,save 1.bmp is black ??? - 05-10-2010 , 07:54 AM






Bitmap bmpSource = new Bitmap(@"c:\1.bmp");
bmpSource.Clone();
Graphics gSource = Graphics.FromImage(bmpSource);


Bitmap bmpDest = new Bitmap(680, 400); // double the size
Graphics gDest = Graphics.FromImage(bmpDest);
IntPtr dcSource = gSource.GetHdc();
IntPtr dcDest = gDest.GetHdc();

GDI32_DLL.StretchBlt(dcDest, 0, 0, bmpDest.Width,
bmpDest.Height, dcSource, 0, 0,
bmpSource.Width, bmpSource.Height,
GDI32_DLL.TernaryRasterOperations.SRCCOPY);

gSource.ReleaseHdc(dcSource);
gDest.ReleaseHdc(dcDest);

bmpDest.Save(@"c:\6.bmp", ImageFormat.Bmp);
MessageBox.Show("Finished Saving Image");

Reply With Quote
  #2  
Old   
Jeff Johnson
 
Posts: n/a

Default Re: why ,save 1.bmp is black ??? - 05-10-2010 , 09:11 AM






"etjon" <etjon (AT) discussions (DOT) microsoft.com> wrote


Quote:
Bitmap bmpSource = new Bitmap(@"c:\1.bmp");
bmpSource.Clone();
Graphics gSource = Graphics.FromImage(bmpSource);


Bitmap bmpDest = new Bitmap(680, 400); // double the size
Graphics gDest = Graphics.FromImage(bmpDest);
IntPtr dcSource = gSource.GetHdc();
IntPtr dcDest = gDest.GetHdc();

GDI32_DLL.StretchBlt(dcDest, 0, 0, bmpDest.Width,
bmpDest.Height, dcSource, 0, 0,
bmpSource.Width, bmpSource.Height,
GDI32_DLL.TernaryRasterOperations.SRCCOPY);

gSource.ReleaseHdc(dcSource);
gDest.ReleaseHdc(dcDest);

bmpDest.Save(@"c:\6.bmp", ImageFormat.Bmp);
MessageBox.Show("Finished Saving Image");
I don't know, but if all you're trying to do is resize 1.bmp, why not:

using (Bitmap source = Bitmap.FromFile(@"c:\1.bmp"))
using (Bitmap resized = new Bitmap(source, 640, 400))
{
resized.Save(@"c:\6.bmp", ImageFormat.Bmp);
}

And for reference, the second line of your code:

bmpSource.Clone();

does absolutely nothing. Cloning returns a NEW object; it does not modify an
existing object.

Reply With Quote
  #3  
Old   
etjon
 
Posts: n/a

Default Re: why ,save 1.bmp is black ??? - 05-11-2010 , 08:57 PM



Thank your Reply,

The second line bmpSource.Clone() , It's test code ,sorry ,
I want to resize it and use socket send this picture or show form,
if i write to file and load file from I/O , It's to slow,but i code is
right ,
why not save it is black color ,because i see my picture is black color in
form .
So i write bmpDest.Save(@"c:\6.bmp", ImageFormat.Bmp),is my test code

Ps: My English is to bad...


"Jeff Johnson" wrote:

Quote:
"etjon" <etjon (AT) discussions (DOT) microsoft.com> wrote in message
news:AC73DE43-273A-4EA1-97B1-B9D3324413AB (AT) microsoft (DOT) com...

Bitmap bmpSource = new Bitmap(@"c:\1.bmp");
bmpSource.Clone();
Graphics gSource = Graphics.FromImage(bmpSource);


Bitmap bmpDest = new Bitmap(680, 400); // double the size
Graphics gDest = Graphics.FromImage(bmpDest);
IntPtr dcSource = gSource.GetHdc();
IntPtr dcDest = gDest.GetHdc();

GDI32_DLL.StretchBlt(dcDest, 0, 0, bmpDest.Width,
bmpDest.Height, dcSource, 0, 0,
bmpSource.Width, bmpSource.Height,
GDI32_DLL.TernaryRasterOperations.SRCCOPY);

gSource.ReleaseHdc(dcSource);
gDest.ReleaseHdc(dcDest);

bmpDest.Save(@"c:\6.bmp", ImageFormat.Bmp);
MessageBox.Show("Finished Saving Image");

I don't know, but if all you're trying to do is resize 1.bmp, why not:

using (Bitmap source = Bitmap.FromFile(@"c:\1.bmp"))
using (Bitmap resized = new Bitmap(source, 640, 400))
{
resized.Save(@"c:\6.bmp", ImageFormat.Bmp);
}

And for reference, the second line of your code:

bmpSource.Clone();

does absolutely nothing. Cloning returns a NEW object; it does not modify an
existing object.


.

Reply With Quote
  #4  
Old   
Family Tree Mike
 
Posts: n/a

Default Re: why ,save 1.bmp is black ??? - 05-11-2010 , 09:38 PM



On 5/11/2010 9:57 PM, etjon wrote:
Quote:
Thank your Reply,

The second line bmpSource.Clone() , It's test code ,sorry ,
I want to resize it and use socket send this picture or show form,
if i write to file and load file from I/O , It's to slow,but i code is
right ,
why not save it is black color ,because i see my picture is black color in
form .
So i write bmpDest.Save(@"c:\6.bmp", ImageFormat.Bmp),is my test code

Ps: My English is to bad...


"Jeff Johnson" wrote:

"etjon"<etjon (AT) discussions (DOT) microsoft.com> wrote in message
news:AC73DE43-273A-4EA1-97B1-B9D3324413AB (AT) microsoft (DOT) com...

Bitmap bmpSource = new Bitmap(@"c:\1.bmp");
bmpSource.Clone();
Graphics gSource = Graphics.FromImage(bmpSource);


Bitmap bmpDest = new Bitmap(680, 400); // double the size
Graphics gDest = Graphics.FromImage(bmpDest);
IntPtr dcSource = gSource.GetHdc();
IntPtr dcDest = gDest.GetHdc();

GDI32_DLL.StretchBlt(dcDest, 0, 0, bmpDest.Width,
bmpDest.Height, dcSource, 0, 0,
bmpSource.Width, bmpSource.Height,
GDI32_DLL.TernaryRasterOperations.SRCCOPY);

gSource.ReleaseHdc(dcSource);
gDest.ReleaseHdc(dcDest);

bmpDest.Save(@"c:\6.bmp", ImageFormat.Bmp);
MessageBox.Show("Finished Saving Image");

I don't know, but if all you're trying to do is resize 1.bmp, why not:

using (Bitmap source = Bitmap.FromFile(@"c:\1.bmp"))
using (Bitmap resized = new Bitmap(source, 640, 400))
{
resized.Save(@"c:\6.bmp", ImageFormat.Bmp);
}

And for reference, the second line of your code:

bmpSource.Clone();

does absolutely nothing. Cloning returns a NEW object; it does not modify an
existing object.


.

For optimal speed, you may find using a MemoryStream to save and load
the image will work. I'm not sure if you tried Jeff's code, but it does
work fine for an image here that I tested.

--
Mike

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.