473,788 Members | 3,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GIF to JPEG over white

Hi all,

I am converting image files of various formats to JPEG using:

System.Drawing. Image img = System.Drawing. Image.FromFile( myfilepath);

Works great except that transparent GIF's are over a black background
instead of white. What would be the simplest way to convert GIF's to an
Image object over a white background?

I have tried the following:

System.Drawing. Image img = new Bitmap(myfilepa th);
Bitmap bmp = new Bitmap(img.Widt h, img.Height);
Graphics gfc = Graphics.FromIm age(bmp);
gfc.Clear(Color .White);
gfc.DrawImage(i mg, 0, 0);
img = bmp;

This does work for the GIF's over white, but then sometimes when a JPEG
runs through this code, it gets resized, so I'm not convinced this is
the best route.

Thanks in advance,
Alyssa

Aug 29 '06 #1
1 2046
Hi,

bm*****@hotmail .com napisał(a):
Hi all,

I am converting image files of various formats to JPEG using:

System.Drawing. Image img = System.Drawing. Image.FromFile( myfilepath);

Works great except that transparent GIF's are over a black background
instead of white. What would be the simplest way to convert GIF's to an
Image object over a white background?

I have tried the following:
I recommend these changes in your code:

System.Drawing. Image img = new Bitmap(myfilepa th);
PixelFormat pixFormat=img.P ixelFormat;
if( pixFormat==Pixe lFormat.Format8 bppIndexed
|| Image.IsAlphaPi xelFormat(pixFo rmat) ) {
Bitmap bmp = new Bitmap(img.Widt h, img.Height);
using( Graphics gfc = Graphics.FromIm age(bmp) ) {
gfc.Clear(Color .White);
gfc.DrawImageUn scaled(img, 0, 0);
}
Image oldImg=img;
img = bmp;
oldImg.Dispose( );
}
This does work for the GIF's over white, but then sometimes when a JPEG
runs through this code, it gets resized, so I'm not convinced this is
the best route.
These changes can assure you that there's no way to draw JPEG
till it has no alpha channel.

Cheers! & HTH
Marcin
Aug 30 '06 #2

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

Similar topics

0
3789
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black and white CCITT4 compressed files (frames) inside the tiff. Every now and then I receive a mixture of black and white CCITT4 and JPEG compressed files, and sometimes just multi-page tiffs with JPEG only. The code runs great when dealing with the...
6
5431
by: Robert | last post by:
Hi I searching in other groups replay but .... :-( Wy my code (print ("<P> <IMG
21
21346
by: cman | last post by:
does anyone know why i can't generate images with: header("Content-type:image/jpeg"); imagejpeg($img_number); i've tried different examples but i always get a text output as if the header doesn't make a difference at all. <?php //random_number.php $img_number = imagecreate(100,50);
5
4734
by: TheGanjaMan | last post by:
Hi everyone, I'm trying to write up a simple image stamper application that stamps the Exif date information from the jpegs that I've taken from my digital camera and saves the new file with the date stamped on the lower right part of the picture. (I'm not an advanced programmer so my code may not be 100% efficient - sorry, I'm still learning) Everything works fine until the saving part. I've been able to read the file into a...
1
1064
by: bmjnine | last post by:
Hi all, I am converting image files of various formats to JPEG using: System.Drawing.Image img = System.Drawing.Image.FromFile(myfilepath); Works great except that transparent GIF's are over a black background instead of white. What would be the simplest way to convert GIF's to an Image object over a white background?
0
2225
by: Jack Wu | last post by:
Hi I've spent a good majority of my day trying to figure out how to have PIL 1.1.5 working on my OSX 10.3.9_PPC machine. I'm still stuck and I have not gotten anywhere. Could somebody please help me... I've scoured all the documentation, google, and mailing lists to no avail. I believe the problem may lay in a jpeglib problem with OSX 10.3.9, or a python paths problem.
4
3820
by: Greg | last post by:
I've searched everywhere for a solution Microsoft .NET Framework V 2.0.50727 AutoEventWireup="false" image2.aspx resize an image on the fly but Page_Load is triggered twice: Any suggestion? Here is the code behind:
1
1397
by: R.A.F. | last post by:
Hi, I have a splash form which has a background JPEG image (back mainly with some blue and white logo). on this form i want to display a text which will be updated dynamically to reflect the progression of application loading and checking. however, even if i setup the text in white, the whole label rectangle is transparent and reflect the color of the application background.
0
1733
by: =?Utf-8?B?TWFyazEyMw==?= | last post by:
I have two pieces of VB.NET code below: a) Sends an email b) Returns a programmatically created jpeg image to a webpage. How can I embed the programmatically created jpeg into an HTML formatted email (without saving the jpeg to disk)? Code a) ======
0
9655
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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
10172
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...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
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
3
2894
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.