Saving image in applet
i used the following code to save a image it displays from applet.it works fine in appletviewer
BufferedImage expImage = new BufferedImage( (int)this.getWidth(), (int)this.getHeight(), BufferedImage.TYPE_INT_RGB );
Graphics g2d = expImage.getGraphics();
// draftGrid.update(g2d);
this.update(g2d);
g2d.dispose();
OutputStream out = new FileOutputStream( "guru.jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(expImage);
out.flush();
out.close();
expImage.flush();
but when i run it in html through my web server the image does' get saved and it the exception i go is
Status code:404 request:R( j
ava/awt/image/BufferedImage.class + null) msg:null
what should i go to save a image from applet throgh browser
Hello,
This is what I am doing through a servlet call.
If you are just going to let the user download the image you could try the following:
// This works if we are just going to download the image as is
URL url = new URL(request.getParameter("imageURL"));
response.setContentType("image/gif");
response.setHeader("Content-Disposition", "attachment; "+
"filename=\"image.gif\"");
byte buf[] = new byte[1024];
InputStream inputStream = url.openStream();
ServletOutputStream out = response.getOutputStream();
//Read and Write
while(inputStream.read(buf) != -1)
out.write(buf);
out.flush();
out.close();
Or if you are going to manipulate the image a bit before they download it you could try the following:
URL url = new URL(request.getParameter("imageURL"));
response.setContentType("image/gif");
response.setHeader("Content-Disposition", "attachment; "+
"filename=\"image.gif\"");
// use ImageIcon because we are getting the image from a
// URL which might be slow - it has the MediaTracker built right in
javax.swing.ImageIcon ii = new javax.swing.ImageIcon(url);
Image image = ii.getImage(); // now the pixel data is in memory
// get the height and width of the loaded image
int width = image.getWidth(null);
int height = image.getHeight(null);
// create a rectangle as big as the image
Rectangle drawRect = new Rectangle(10, 10, width, height);
BufferedImage bufImage = new BufferedImage(width,
height, BufferedImage.TYPE_INT_RGB);
// get the graphics so you can draw on it
Graphics2D g = bufImage.createGraphics();
// create a nicce white background for the image
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
// reset the color
g.setColor(Color.black);
// add the image
g.drawImage(image, 0, 0, null);
// add any other things you want as well
g.drawString("Just a string", 10, 10);
// create the output stream
ServletOutputStream out = response.getOutputStream();
JPEGImageEncoder jpegImageEncoder = JPEGCodec.createJPEGEncode(out);
// encode it
jpegImageEncoder.encode(bufImage);
out.flush();
out.close();
Hope that this helps.
Mike
Similar Messages
-
Saving images from applet back to the host
Hi,
I am trying to save an image (or a buffered image) from an applet back to its original host . Is there a way to do this without using a servlet at the server's end?
An earliest response would be appreciated.
Thanks in advance.Thanks to all of you for your help. Your replies have been helpful to me.
Atlast I'm done with my problem. I am able to write my image to the host.
I have converted the Image(buffered image) into a byte stream
ImageIO.write(bimg,imgType,bos);
converted the stream to byte array:
byte[] b=bos.toByteArray();
and used HttpURLConnection to write the byte array to the host.
Thank you. -
Black background of saved image file.
Hello All,
My code is set up to create an image then save the image into a file in JPEG format. Everything works well except the background of the saved image is balck. How can I get a white background on the saved file?
I have posted my code below. I have allocated 10 duke dollars for the person solves who this? Thank You!!!!
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import com.sun.image.codec.jpeg.*;
import java.io.*;
import java.awt.image.BufferedImage;
public class Test2 extends JApplet {
public void init() {
//Initialize drawing colors
setBackground(Color.white);
setForeground(Color.black);
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Dimension d = getSize();
int gridWidth = d.width / 6;
int gridHeight = d.height / 2;
// fill Rectangle2D.Double (red)
g2.setPaint(Color.red);
g2.fill(new Rectangle2D.Double(100, 100, 100, 100));
g2.setPaint(Color.black);
g2.drawString("My Rectangle", 125, 85);
public static void main(String s[]) {
JFrame f = new JFrame("Test2");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
JApplet applet = new Test2();
f.getContentPane().add("Center", applet);
applet.init();
f.pack();
f.setSize(new Dimension(400,300));
f.show();
saveAsJPEG(applet, 1.0F, "myJPEG.jpg");
public static void saveAsJPEG(Component component, float quality, String filename) {
try {
Dimension d = component.getSize();
BufferedImage bimage = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
component.paint(bimage.createGraphics());
Graphics2D g = (Graphics2D)bimage.getGraphics();
g.setPaint(Color.white);
if(!filename.endsWith(".jpg"))
filename += ".jpg";
OutputStream out = new FileOutputStream(filename);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
// Create JPEG encoder
JPEGEncodeParam jpegParams = encoder.getDefaultJPEGEncodeParam(bimage);
jpegParams.setQuality(quality, false);
// Set quality to (quality*100)% for JPEG
encoder.setJPEGEncodeParam(jpegParams);
encoder.encode(bimage);
// Encode image to JPEG and send to browser
out.close();
catch (Exception e) {
System.out.println(e);
}I've added 2 lines to your paint, it works now.
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Dimension d = getSize();
int gridWidth = d.width / 6;
int gridHeight = d.height / 2;
// make a white background
g2.setPaint(Color.white);
g2.fill(new Rectangle2D.Double(0, 0, d.width, d.height));
// fill Rectangle2D.Double (red)
g2.setPaint(Color.red);
g2.fill(new Rectangle2D.Double(100, 100, 100, 100));
g2.setPaint(Color.black);
g2.drawString("My Rectangle", 125, 85);
} -
Impossible to save an image in applet?
I have been working on saving an image in Java applet for a week. But I failed to generate new image file on the disk. I'm using Java SDK1.4.0_03 and JAI 1_1_1_01. I found a topic "JAI TIFF Encoding Problem" mentioned that it should give permission to the Applet. I'm wondering if my problem is caused by the permission of Applet. But how to change the permissio of Applet? Otherwise is it impossible to save the image in Applet? Thanks your replay.
Re : Thanks your replay.
I have been working on saving an image in Java applet
for a week. But I failed to generate new image file on
the disk. I'm using Java SDK1.4.0_03 and JAI 1_1_1_01.
I found a topic "JAI TIFF Encoding Problem" mentioned
that it should give permission to the Applet. I'm
wondering if my problem is caused by the permission of
Applet. But how to change the permissio of Applet?
Otherwise is it impossible to save the image in
Applet? Thanks your replay. You're welcome :) -
has anyone had the problem where, when they select option and tap an image (in my case i pulled one from my email using an image i uploaded from my drive) and gotten an error that says "there was an error saving image" and your only option is 'ok'? i've read other forums and understand that jpeg's are the ideal form, and this had a .jpg extension.
any thougths anyone?
so many thanks in advance.
-wren
Post relates to: Pixi Plus p121vzw (Verizon)hey thanks , but my jdbc pool and driver is fine. what may be the problem and I am not able to change the type to BlobDomain in eo. The type i Blob only may be this is the problem how can I change it to Blob Domain
-
Saving images from camera raw in new CC suite
Hi Im having trouble re saving images from new adobe cc bridge camera raw, images once saved then show in bridge with no adjustments done in camera raw and the images are downsized to KB size images even from a 9.20mb raw image, Ive looked at setting or rather preferences and totally lost please help!!
Thank you
JonThis forum is actually about the Cloud, not about using individual programs
Once your program downloads and installs with no errors, you need the program forum
If you start at the Forums Index http://forums.adobe.com/index.jspa
You will be able to select a forum for the specific Adobe product(s) you use
Click the "down arrow" symbol on the right (where it says ALL FORUMS) to open the drop down list and scroll
http://forums.adobe.com/community/bridge -
Saving image to a folder not working on azure
I am saving image
files to a folder in my application and saving its path in database . Image uploads working fine when I am running locally
and its path is also storing.When I deployed it on azure it
gives an error that " An error occurred while processing your request ". I have two tables in my database . First one where text is saved is working fine on azure but image upload thrown this error.
I am using this code
to upload
image and its works fine when I am running locally. Need help ?Hi,
Have you made any progress ?
May I ask what application is it that you are running ? You mentioned that it works locally but not when deploying to Azure. Have you checked the connections strings?
If you are still having any difficulty in understanding the code, perhaps you could post it on the below blog.
http://blogs.msdn.com/b/onecode/archive/2014/08/28/sample-of-aug-28-how-to-store-the-images-in-sql-azure.aspx
Regards,
Mekh. -
Problem with display of images in applets
Hi all,
When I run this program, the appletviewer window is showing no output (i.e. no image). I'm using the netbeans IDE 5.0.
Blue hills.jpg is present in both the src folder and build folder.
* <applet code="image" width =800 height=600>
* <param name="img" value="Blue hills.jpg">
* <\applet>
import java.awt.*;
import java.applet.*;
public class image extends Applet {
Image img;
public void init() {
img=getImage(getDocumentBase(), getParameter("img"));
public void paint(Graphics g){
g.drawImage(img,0,0,this);
Please help in figuring out the problem....It will be looking for it in the folder with the HTML that invokes the applet.
If you want to pack the image in with the applet then use getResource instead.
And spaces in the name are probably not the best idea. -
Data type for Saving Image in SQL database
Hi,
Which is the best way for saving images in the database? Filestream or Varbinary(max)?. Will the Varbinary max comsume much space or it will only take the actual size of the data?I've used FILETABLE for storing images in SQL 2012
You can configure it to have transact and non transact access if you want
see
http://visakhm.blogspot.in/2012/07/working-with-filetables-in-sql-2012.html
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
How do I stop Firefox from grabbing my saved images and coverting them to Firefox?
I am working on images in Dreamweaver and Adobe Photoshop, and when I try to save them, Firefox coverts them into Firefox images with a Firefox icon and then I can't edit them properly in Photoshop or Dreamweaver. How do I stop Firefox from grabbing my saved images? in English
I will try that, but it's pretty time consuming to have to check that for each of my images. I am a web designer and I work with a lot of images.
Is there any way to set that globally for all of my saved images? -
Saving image using mobile into sap R/3
We are using sap mobile platform version 2.3 and our client requirement is to save images using mobile apps.
We already saved images in mime repository but for this we have to required client modifiable , but due to security reason we can't do this.
Please Help.Hi Nilesh ,
I had a scenario to attach image to pr05 transaction from mobile, so that when click view attachment button in pr05 i can see the image . My code is based on that .
it is the function module with import parameter base64 string and filename ,last three letters of the file name proceeding the . is the extension
in your case you need to create custom object type instead of BUS2089 .
Do research regarding that ..
-->Local Workare declaration.
DATA : ls_fol_id TYPE soodk,
ls_obj_id TYPE soodk,
ls_obj_data TYPE sood1,
ls_content TYPE soli,
ls_folmem_k TYPE sofmk,
ls_note TYPE borident,
ls_object TYPE borident.
**--> Local internal table declaration.
DATA : lt_content TYPE STANDARD TABLE OF soli,
lt_url_tab TYPE STANDARD TABLE OF so_url,
lt_objhead TYPE STANDARD TABLE OF soli.
**--> Local variable declaration.
DATA : lv_filename TYPE string,
lv_file_name_with_path TYPE chkfile,
lv_stripped_name TYPE string,
lv_name TYPE char30,
lv_url_tab_size TYPE sytabix,
lv_ep_note TYPE borident-objkey.
ls_object-objtype = 'BUS2089'.
ls_object-objkey = '001095510000020022'.
ls_obj_data-objdes = I_FILE_NAME.
ls_obj_data-file_ext = I_FILE_EXT.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = I_FILE
TABLES
binary_tab = lt_content.
CALL FUNCTION 'SO_CONVERT_CONTENTS_BIN'
EXPORTING
it_contents_bin = lt_content[]
IMPORTING
et_contents_bin = lt_content[].
**--> Getting folder ID to save data
CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
EXPORTING
region = 'B'
IMPORTING
folder_id = ls_fol_id
EXCEPTIONS
communication_failure = 1
owner_not_exist = 2
system_failure = 3
x_error = 4
OTHERS = 5.
IF sy-subrc = 0.
ls_obj_data-objsns = 'O'.
ls_obj_data-objla = sy-langu.
ls_obj_data-objlen = LINES( lt_content ) * 255.
CLEAR ls_content.
CONCATENATE '&SO_FILENAME=' I_FILE_NAME '.' I_FILE_EXT INTO ls_content.
APPEND ls_content TO lt_objhead.
**-->To Create an Object and Move to a Folder
CALL FUNCTION 'SO_OBJECT_INSERT'
EXPORTING
folder_id = ls_fol_id
object_hd_change = ls_obj_data
object_type = 'EXT'
IMPORTING
object_id = ls_obj_id
TABLES
objcont = lt_content
objhead = lt_objhead
EXCEPTIONS
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
dl_name_exist = 4
folder_not_exist = 5
folder_no_authorization = 6
object_type_not_exist = 7
operation_no_authorization = 8
owner_not_exist = 9
parameter_error = 10
substitute_not_active = 11
substitute_not_defined = 12
system_failure = 13
x_error = 14
OTHERS = 15.
IF sy-subrc = 0 AND ls_object-objkey IS NOT INITIAL.
* COMMIT WORK AND WAIT.
ls_folmem_k-foltp = ls_fol_id-objtp.
ls_folmem_k-folyr = ls_fol_id-objyr.
ls_folmem_k-folno = ls_fol_id-objno.
ls_folmem_k-doctp = ls_obj_id-objtp.
ls_folmem_k-docyr = ls_obj_id-objyr.
ls_folmem_k-docno = ls_obj_id-objno.
lv_ep_note = ls_folmem_k.
ls_note-objtype = 'MESSAGE'.
ls_note-objkey = lv_ep_note.
**-->Link the object ID to trip No.
CALL FUNCTION 'BINARY_RELATION_CREATE_COMMIT'
EXPORTING
obj_rolea = ls_object
obj_roleb = ls_note
relationtype = 'ATTA'
EXCEPTIONS
no_model = 1
internal_error = 2
unknown = 3
OTHERS = 4.
IF sy-subrc = 0.
* COMMIT WORK AND WAIT.
ENDIF.
ENDIF. " SO_OBJECT_INSERT
ENDIF. " SO_FOLDER_ROOT_ID_GET
ENDFUNCTION. -
I save a lot of images using firefox, often times from a large batch or series of images. It used to be that I would click on a previously saved image and the entire file name including the file extension (i.e. image_example.jpg) would appear in the "save as" line. Now when I click on a previously saved file, the file name appears without the file extension (i.e. image_example). Which means I have to manually type .jpg every time. For a large collection of images that I am hoping to use the same root file name and then add chronological numbers at the end, this has become incredibly frustrating, especially as it is a previously unnecessary task.
I am using a new Macbook Pro and maybe there's something Apple related to this...? It did not happen on my old PowerBook G4. I have file extensions turned on in System Preferences.
It should be noted that I have searched high and low and have even gone into the Apple Genius Bar where they were just confused as I was and of course ended by urging me to use Safari (shocker!) as it has all kinds of new extensions and bells and whistles. I seriously feel alone on an island with this dumb, hard to google problem. Thanks so much for any help anyone out there might have.
I mean: is this as simple as changing a setting in about:config?
Your assistance is greatly appreciated.Thanks for your response Mylenium, however like I mentioned multiple times, I did change all of my trackpad/scrolling settings in system preferences. And if I wanted to use a normal mouse (or a tablet), I would've gotten an iMac instead of a MacBook Pro. I travel often and work all over the place, not always with access to a decently sized workspace that would be required for using a mouse or tablet.
-
Saving image in ms sql database.
Hi all, i have a problem saving image in the database.i used
request.getParameter("imagename"), to get the content of the textfield in the html file but the problem is that it omits the filepath and gives me just the image name and that gives me an error.. Pls help meYour actual problem is less or more web browser related. The right way is that the browser should only send the filename, but a certain widely used browser developed by a team in Redmond would send the full file path as it is at the client side, which is completely wrong.
The bigger picture what you're trying to achieve, uploading a file from the client to the server, shouldn't be done that way, simply because this isn't going to work at all if the client runs at a completely different machine on the other side of the network than where the server runs. You need to send the actual file contents to the server. Just set the form's enctype to multipart/form-data and parse the body of the request to get the actual file contents. To ease the work I recommend you to use Apache Commons FileUpload API for parsing the multipart/form-data request. Go to their homepage and check out the 'User guide' and 'Frequently Asked Questions' how to use it and for some tricks. -
How to move multiple images in applet
Hi,how to move multiple images in applet or random images in applet .
Means moving images.gif around the applet with different starting point ,help me to create that move method ..why don't you check the tumbling duke applet as provided free in this site? :-)
-
hi every body.
I want to display images in an applet when i invoke it from the jsp page . it is not working. the code is as follows.
<html>
<body>
<jsp:plugin type = "applet"
code ="Welcome.class"
width="475" height = "350" >
</jsp:plugin>
</body>
</html>
while the code of "Welcome.java" is as follows.
ImageIcon image = new ImageIcon("aa.gif");
JButton button = new JButton(image);
i have placed the aa.gif file in the same directory where i placed the Welcome.class and the jsp file.
when i run this program the i recieve the message that the applet is not loaded.
can some body help me how to place images in applets.
thanks.You should be able to test that applet on you hard drive first. If it works check the case of the image file.
Web servers look for case. If you are asking for ImageIcon img = new ImageIcon("abc.gif") and what is loaded on your web server is "abc.GIF" it won't find it. Same goes for basic HTML tags like
<Img src=abc.gif>. But it will find it on you hard drive when you run the applet there.
Maybe you are looking for
-
Adobe Reader 9 crashes when opening approximately 10% to 20% of the pdfs in my collection. The remaining 80% to 90% work without problems. The pdfs are launched by double-clicking the pdf file from Windows Explorer. The crashes occur with both v9.0 a
-
Hi all, When I publish a web page in Iweb it goes to preferences. I can't update the web page on the web like I did on Tiger?????????? [email protected]
-
After a several weeks wait, I finally received my camera connection kit today. It's small, simple, and easy to use - just plug it in, and it works - at least that was my experience. I bought it primarily to download photos from my camera, and be able
-
hi im thinking about making a system what i want it to do is this: have a grid of buttons when a certain button is clicked it will save the setting and go to another menue and give you more options that you can choose from after you are done selectin
-
Any ideas why I have emails received on iphone but are deleted from p.c ?.
Does anyone have any ideas as to why I receive Emails on my Iphone, but they are deleted from my p.c.?