473,385 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Editing Pictures

this is my first question here and i hope it will be helpfull.

I'm trying to upload a picture to pictureBox and then to rotate this picture
but my problem is that when i want to save the picture after I rotate it he send me error message and told me that another program use this file (probably my program).

any ideas how to overcome this problame?
Nov 7 '08 #1
10 1394
Plater
7,872 Expert 4TB
I imagine you are opening the file with something like Bitmap.FromFile (or Image.FromFile)
It keeps the filehandle open. What you would do is .Clone() it to another Image/Bitmap object. Then .Dispose() of the first one (closes the file handle)

You now have you picture object and the filehandle is closed. You are free to overwrite the file.
Nov 7 '08 #2
thanks, but it's still don't work
is there any other way to open file not with image.fromFile
so that the stream will stay close?
Nov 7 '08 #3
Plater
7,872 Expert 4TB
Ok, my mistake, the Clone() keeps the filehandle open too.

This seemed to work though:
Expand|Select|Wrap|Line Numbers
  1. string fn= @"C:\myjpg.jpg";
  2.  
  3. Bitmap bm = (Bitmap)Bitmap.FromFile(fn);
  4. Bitmap bm2 = (Bitmap)bm.GetThumbnailImage(bm.Width, bm.Height, null, IntPtr.Zero); 
  5. bm.Dispose();
  6.  
  7. bm2.Save(fn);
  8.  
Nov 7 '08 #4
thanks again, but i think its more complicated im my program because i save this picture in more then one copy.
Nov 7 '08 #5
Plater
7,872 Expert 4TB
What do you mean more then one copy?
Nov 7 '08 #6
i mean that i upload the picture to two pictureBox
and i save the images in arraylist, but now its ok, i change my program so that you can rotate the picture just at the first time you upload it.
hope you understand what i mean, but thanks anyway :)
Nov 7 '08 #7
Plater
7,872 Expert 4TB
Oh ok so you have two copies of it open?

I would make a function like:
Expand|Select|Wrap|Line Numbers
  1. private Image OpenImageFile(string filename)
  2. {
  3. Image retval;
  4. Bitmap bm = (Bitmap)Bitmap.FromFile(fn); 
  5. Image = bm.GetThumbnailImage(bm.Width, bm.Height, null, IntPtr.Zero);  
  6. bm.Dispose(); 
  7. return retval;
  8. }
  9.  
So no matter how many times I open the file, it's always closed and I have an image object for it.
Nov 7 '08 #8
good idea , i try it, thanks
Nov 7 '08 #9
Frinavale
9,735 Expert Mod 8TB
I've changed the title of your thread to something that represents the problem you're facing. In the future please use an appropriate title for your thread. To help get your .NET questions answered more quickly, check out this thread for more information on how to properly format your titles.

-Moderator Frinny
Nov 7 '08 #10
tlhintoq
3,525 Expert 2GB
Might I also suggest that putting it into the picture box when you know you are going to rotate it as the next step seems a little odd.

I would think you would load the image, rotate the image, then once you have what you really want - then - you would display it in the picture box.
Nov 8 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: JakeC | last post by:
Hey all, I'm currently redesigning a website that a friend and I started about a year ago. It is a daily surf report so when choosing the best script/language to use for the new design, I found...
10
by: David T. Ashley | last post by:
Hi, I'd like to do some basic graphics. For example, if you look at: http://www.marshallaviationcenter.com the banner graphics at the top that apparently used an image editor with some...
12
by: Wadim Grasza | last post by:
I want to store and display (on a form or a report) multiple pictures per record in an access database. The pictures are not stored within the database. They are stored as files and the database...
0
by: Nick - Beccles UK | last post by:
I wish to be able to add some data to over 1000 pictures I have in one of my Picture Libraries, and as some of the data was repeatative wondered if anybody knows of away of editing the data fieids...
3
by: Manish | last post by:
I am developing a photo gallery. 1. The user will be able to upload the photo a) Edit the photo using various GD library functions viz. flip, rotate, ... 2. AJAX is implemented in a small...
0
by: google | last post by:
is it posable to let a user upload a video/audio file and then i edit it like you can with pictures? eg. change reselution, put a pre recorded introduction to it (branding it to a website) or even...
15
by: lbrtchx | last post by:
I am trying to write up a page with Math formulas (statistical ones) ~ http://www.geocities.com/tekmonk2005/OnLineStats02.html ~ The thing is that I am not able to make it look OK using HTML. I...
16
Frinavale
by: Frinavale | last post by:
I took a video on the weekend of a war re-enactment with my new camera. It turned out to be 900MB and since I was taking pictures at the same time there's points where the video freezes and you can...
2
by: Chris Paxton | last post by:
I have a fairly basic VB.NET application that I converted from VS2003 to VS2005 and now it crashed the VS2005 IDE pretty regularly while trying to use the form designer. I've removed any 3rd...
4
by: Zeljko Bilandzija | last post by:
Hy, could someone help me in this: In design mode, i want to put pictures in database. I made column named pics, and its type as image. How can I put pictures or some address of these pictures...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...

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.