Jump to content
Reliance Jio & Reliance Mobile Discussion Forums
Sign in to follow this  
abhay

Anyone In .net

Recommended Posts

here guys this is what i wanna do

take a image modify it and save it

the class which i am using is System.Drawing.Bitmap

Bitmap objBitmap1 = new Bitmap(this.textBox1.Text);
Bitmap objBitmap2 = new Bitmap(objBitmap1.Width,objBitmap1.Height);

// copy and modification code for objBitmap2 and then store it in a new file 


// here is how i save
objBitmap2.Save(this.textBox3.Text);

now the problem with saving is when i save this way everythings fine except that the file size increases to MB's

a mere 100 kb jpeg file turns out to be 4-5 mb jpeg file

and when i use a overloaded function of save ie

public void Save(

string filename,

ImageFormat format

);

and specify a format, the file size is fine but then the image tend pixels change

this is what i dont need i need the same exact pixel data as the image in objBitmap2 to b saved in d file

Share this post


Link to post
Share on other sites

well, buddy JPEG files are lossy compression format, so the jpeg pictures are actually COMPRESSED files.

If u convert a jpeg file to an UMCOMPRESSED Bitmap file, it is going to increase in size,plain and simple.

Save it in JPEG format.

Share this post


Link to post
Share on other sites

yeah i did save it into a jpeg

objBitmap2.Save(this.textBox3.Text,System.Drawing.Imaging.ImageFormat.Jpeg);

but the problem with it is IT CHANGES THE PIXELS :victory:

as in if the first pixel has RGB(10,10,10)

it changes the values to some other ones like RGB(13,15,20)

what i want is exact same replica of the image in the saved file (pixel wise) :victory:

please help its imp for me :victory:

Share this post


Link to post
Share on other sites

set bits for optimized as wells as progressive JPEG encoding with upto 30% or more compression, that should do the trick.

Share this post


Link to post
Share on other sites

those are properties of JPEGs. But why do you care what pixels color values are stored? And how did you manage to blow up a 100KB file to MBs? :D

Share this post


Link to post
Share on other sites

ok here is what i did

using c#

1) i loaded a image (jpg) into THE bitmap class in .net

2) made another bitmap class and intantiated it to the same hieght /width /PixelFormat as the prevoius one

like this

Bitmap objBitmap1 = new Bitmap(this.textBox1.Text);
			Bitmap objBitmap2 = new Bitmap(objBitmap1.Width,objBitmap1.Height,objBitmap1.PixelFormat);

3) now i copied from former (objBitmap1) object to other bitmap object(objBitmap2) PIXEL BY PIXEL

like this

for (int intY = 0;intY <= objBitmap1.Height - 1; intY++) 
			{
				for (int intX = 0;intX <= objBitmap1.Width -1;intX++) 
				{
					objBitmap2.SetPixel(intX,intY,objBitmap1.GetPixel(intX,intY));
				}
			}

NOTE :- PIXEL BY PIXEL

4) now when i save objBitmap2 in a file I have TWO options

save it normally OR save it with a format specfied

a) Saves this Image object to the specified file in the specified format.

[C#] public void Save(string, ImageFormat);

:) Saves this Image object to the specified file.

[C#] public void Save(string);

when i use the latter one i get a compressed image but and when even better i get a image which is smaller in size to the orignal one BUT the pixels are changed**

and if i use the former one then the image format is uncompressed but pixels are noe changed**

**by pixels i mean the RGB values in them and even if they are changed in the first save option the diffrence is not visible to a human eye but one can programatically detect the diffrence

i need to creat a exact same replica of the image

Share this post


Link to post
Share on other sites

sorry buddy, you cant do that.

as i told you before , JPEG IS A LOSSY COMPRESSION.

that means that the exact RGB values will never be preserved unless you save it in a NON-LOSSY compression format such as RAW BMP.

and if you do save it in BMP format the size is gonna blow up.

as a suggestion i might like to add is that you could actually write your own progressive compression alogrythm, is quite simple, but then the other problem would be that no other image viewer would be able to open your bitmap.

for a progressive set encoding (compression) what you could do is ...

store repeated RGB value sets into a single counted RGB set for each number of same pixel stored on the same line.

if your image has a high redundancy you'd get a very good compression.

if you want better compression, go in for a huffman.

lookup google for more info on huffman, im not going into the details.

Share this post


Link to post
Share on other sites

abhay, why are all your problems SO weird. Can you please post a sample image and the one saved by your program so we can have a fair idea as to what you really mean? BTW do the physical dimensions of the image change when you save it?

Share this post


Link to post
Share on other sites

as i said nothing NOT even a single PIXEL VALUE changes during the copying if saved by method 1* but the size increases multifolds

BUT BUT BUT if i save it into a JPEG extention using METHOD 2 then the file size remains the same BUT the pixel value changes

*method 1

[C#] public void Save(string);

*METHOD 2

[C#] public void Save(string, ImageFormat);

below is the orignal image

http://img411.imageshack.us/img411/1715/images6vc.jpg

here is a link to a image using method 2 ie specify the image format during save

http://img403.imageshack.us/img403/1471/aa6us.jpg

hehe i cant upload the third image , its using the METHOD 1 and its 3.84 mb

u try it urself c# code

Bitmap objBitmap1 = new Bitmap(@"c:\images.jpg");

Bitmap objBitmap2 = new Bitmap(objBitmap1.Width,objBitmap1.Height,objBitmap1.PixelFormat);

for (int intY = 0;intY <= objBitmap1.Height - 1; intY++)

{

for (int intX = 0;intX <= objBitmap1.Width -1;intX++)

{

objBitmap2.SetPixel(intX,intY,objBitmap1.GetPixel(intX,intY));

}

}

objBitmap2.Save(@"c:\abhay.jpg"); <<- method 1

objBitmap2.Save(@"c:\aa.jpg",ImageFormat.Jpeg); <<- method 2

MessageBox.Show("done");

a) the image size dose not change

b ) the pixel values change ONLY if i save it in a a jpg format

c) if we check the image pixelwise

orignal image == method 1

but

orignal image != method 2 :P which should be coz the image is also a jpg and we are just copying the pixels thats it

PS yup my RnD are most of the time WIERD :lol:

Share this post


Link to post
Share on other sites

abhay, what Static said was correct. I just wanted to be sure so I asked you to post the images.

See, BMP (Bitmap) is a format where each and every pixel's color and location(?) is stored. So when you save it just as a bitmap, each pixel matches the original image.

BUT JPEG is a lossy compression format which means, some of the pixel info is lost. To the eyes, the image will not seem different (lest you use a very high compression factor). So the pixels RGB values differ in the second case.

Share this post


Link to post
Share on other sites

hey static i only replied d third time coz linux guys asked me to upload d image yup i did read ur prevoius post grrrrr :blink:

Share this post


Link to post
Share on other sites

well for my App @present due to the complexity of d stuff i havent included jpeg file only BMP files are accepted

may b d second ver os the app would have support for jpg file lots of R&D left on the jpg format and stuff

at a glance the huffman seems to be useful but dont actully know how to implement it in .net may be some more R&D @ that topic is needed

thx for d info btw

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×