473,725 Members | 2,197 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Image.Save( ..., ImageFormat.Bmp ) slow in simple case

If I read a bitmap image from one file and save it to another the save
operation is slow unless I draw on the image. In other words,

Image inputImage = Image.FromFile( @"c:\temp\sourc e.bmp" );
using ( Graphics g = Graphics.FromIm age( inputImage ) )
{
g.DrawLine( new Pen(Brushes.Whi te), 0, 0, 1, 1 );
}
inputImage.Save ( @"c:\temp\sink. bmp", ImageFormat.Bmp );

is many times faster than

Image inputImage = Image.FromFile( @"c:\temp\sourc e.bmp" );
inputImage.Save ( @"c:\temp\sink. bmp", ImageFormat.Bmp );

So what side effect is created by DrawLine that speeds up the Save?

I have a small console app I called ImageCopy that demostrates what
I'm talking about. The results go like this on my machine using a
3.5Mb .bmp file:

C:\>ImageCopy c:\temp\source. bmp c:\temp\sink.bm p nodrawing
no drawing
READ: 00:00:00.031250 0
DRAW: 00:00:00
SAVE: 00:00:00.343750 0
TOTAL: 00:00:00.375000 0

C:\>ImageCopy c:\temp\source. bmp c:\temp\sink.bm p draw
with drawing
READ: 00:00:00.031250 0
DRAW: 00:00:00
SAVE: 00:00:00.015625 0
TOTAL: 00:00:00.046875 0

The save time differs by a factor of about 20x in this run. On a 5x
slower CPU the difference was more like 60x.

Here's the source for my ImageCopy console application (C#):

using System;
using System.Drawing;
using System.Drawing. Imaging;

namespace ImageCopy
{
class ImageCopy
{
[STAThread]
static void Main(string[] args)
{
DateTime startTotalTime = DateTime.Now;
DateTime startReadTime = DateTime.Now;

Image inputImage = Image.FromFile( args[0] ); // Read
TimeSpan readDuration = DateTime.Now - startReadTime;

DateTime startDrawTime = DateTime.Now;

if ( args.Length == 3 && args[2] == "draw" )
{
Console.WriteLi ne( "with drawing" );
using ( Graphics g = Graphics.FromIm age( inputImage ) )
{
g.DrawLine( new Pen(Brushes.Whi te), 0, 0, 1, 1 );
}
}
else
{
Console.WriteLi ne( "no drawing" );
}
TimeSpan drawDuration = DateTime.Now - startDrawTime;

DateTime startSaveTime = DateTime.Now;

inputImage.Save ( args[1], ImageFormat.Bmp ); // Save
TimeSpan saveDuration = DateTime.Now - startSaveTime;
TimeSpan totalDuration = DateTime.Now - startTotalTime;

Console.WriteLi ne( " READ: " + readDuration.To String() );
Console.WriteLi ne( " DRAW: " + drawDuration.To String() );
Console.WriteLi ne( " SAVE: " + saveDuration.To String() );
Console.WriteLi ne( "TOTAL: " + totalDuration.T oString() );
}
}
I run tests from a .bat file that contains these two lines:

imagecopy c:\temp\source. bmp c:\temp\sink.bm p dontdraw
imagecopy c:\temp\source. bmp c:\temp\sink.bm p draw
Nov 22 '05 #1
0 2161

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
626
by: F. Hall | last post by:
If I read a bitmap image from one file and save it to another the save operation is slow unless I draw on the image. In other words, Image inputImage = Image.FromFile( @"c:\temp\source.bmp" ); using ( Graphics g = Graphics.FromImage( inputImage ) ) { g.DrawLine( new Pen(Brushes.White), 0, 0, 1, 1 ); } inputImage.Save( @"c:\temp\sink.bmp", ImageFormat.Bmp );
4
11742
by: Detlef Huettenbach | last post by:
I was trying to convert a Windows Forms prototype application to an ASP.NET solution that makes use of loading data streams into the Image Web/Windows control. For WinForms no problem. However in ASP.NET, the image control does not display tiffs,pngs,.. still it does display gif-streams. Memory stream writing into a gif- stream of the tiff and other streams likewise fails, although the streams seem to be filled correctly. On top of that,...
2
1196
by: Miguel Dias Moura | last post by:
Hello, I created a page in ASP.Net / VB where i placed an image. The image's file to use should be "images/imgN.gif", where N is the value of the parameter Number passed to the page in the URL. Can someone tell me how to do this? Thank You,
7
3400
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
2
2585
by: Jeronimo Bertran | last post by:
Hello, I am using a rendering aspx page to display a database image on an Image control. When the database record is retrieved, I am saving the bitmap to a session variable for the rendering aspx to load. Here is the code on the rendering page: CODE FOR ImageForm.aspx private void Page_Load(object sender, System.EventArgs e)
6
2774
by: Michael | last post by:
I'm trying to use the Bitmap class's Save Method to save a Bitmap as a GIF. My code runs fine, and converts the image, but the quality is not anywhere close to as good. I know that GIF quality is not a good as a BMP's but, is there a way to convert the image while preserving its quality. Any help would be greatly appreciated. Here's what I have... Public Enum ImageType Bmp = 0 Emf = 1
4
2754
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is that I can't view the source???? The view source is disabled for this page. What causes this?
5
2472
by: Emmi | last post by:
Hi there, just starting in PHP and found some code that would switch out pages depending on link clicked. It worked great loading different pages. Then I thought I would try the same code by calling an image instead of a page. When I use the following code, what happens is the rest of the page loads fine, but instead of getting an image I'm getting junk on the screen. Could anyone tell me what I'm doing wrong? Here is my script: <?php ...
0
1412
by: Erakis | last post by:
Hi, I need to put a very large image as background (1030px X 774px) on the main window of my application. Also, on this window I need to add transparent Usercontrol, Panel and Label. Every time I need to refresh or replace a Usercontrol, the redraw is doing very TOO slow and there some flickering... I try to activate the double buffering but without success. Same refresh speed.
4
5032
by: Marcolino | last post by:
Hi, I have simple needs but I don't know how to implement it. I have application that create Dynamic Button. I need to set the image on this button, getting the icon from a form. So pratically I need to convert dinamically a Form.Icon to Button.Image runtime, but i don't know how. Any help would be appreciated. Many Thanks
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8097
agi2029
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
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
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.