Drawing letters and saving as png-s...

Hi,
I'm kinda new to this platform and I would like to make small app that would be able to take certain characters from a selected font and save them in .png format.
Just curious as to what classes I should start with and stuff like that.
Thanks

[http://java.sun.com/docs/books/tutorial/2d/index.html]
Reading and writing images can be done with javax.imageio.ImageIO

Similar Messages

  • TS3276 Having trouble sending jpeg images as attachments in Mac email.....they go thru as images and PC users can't see the SAVE or QUICK LOOK boxes that Mac mail has.  One friend scrolled over the image, right clicked on it and saved as a PNG file.

    Having trouble sending jpeg images as attachments in Mac email.....they go thru as images and PC users can't see the SAVE or QUICK LOOK boxes that Mac mail has.  One friend scrolled over the image, right clicked on it and saved as a PNG file.

    Apple Mail isn't going to change the format of any of your attachments. it isn't going to corrupt them either.
    Exchange is a transport protocol and server. The issue you describe is not related to Exchange.
    There are many different versions of Microsoft Outlook in use and they all have e-mail bugs. Different versions have different bugs. Some Apple Mail hack to get around a bug in Outlook 2003 may cause the same message to be problematic in Outlook 2000. Fix them both and another issue will cause trouble in Outlook 2007. You can't fix this. Apple can't fix this. Microsoft can and has but that is irrelevant if your recipients are using older versions.
    One specific problem is that Apple Mail always sends image attachments inline, as images, not as iconized files. You can change this with Attachment Tamer. Just be aware that use of this software will break other things such as Stationery. E-mail is just a disaster. To date, no one outside of Apple has ever implemented the e-mail standards from 1993. Apple has continually changed its e-mail software to be more compatible with the de-facto standards that Netscape and Microsoft have unilaterally defined and people documented as "standards" after the fact. The e-mail messages that Apple Mail sends are 100% correct and do not violate any of the original standards from 1993 or the Microsoft/Netscape modifications. The problem is entirely bugs and limitations in various versions of Outlook.

  • Problems opening and saving PNG over network with CS2 and CS3

    using os10.4.11
    photoshop CS2 or CS3
    I've recently tried to save images in PNG format,  small (no more than a couple hundred kilobytes) and found that whenever I tried to save to the server it would hang photoshop and require a force-quit. Saving the same file to the desktop works fine. Copying said file to the network and then trying to open that PNG from the server results in a photoshop hang, while opening that same file from the desktop works fine. I know all about the fact that Adobe doesn't support working over a server, but that's never been an issue at my workplace in all the years I've worked with (never had problems saving/opening any format, no corrupted files ever). If I try to open that same PNG from the server with CS2, same result. If I try to open it over the server using Photoshop CS, or version 7, however, it opens just fine. If I copy the Photoshop CS version of the PNG plugin and replace the PNG plugin installed with CS3 by default, then it seems to work and I can now open and save PNGs anywhere with no problems. Has anyone else had this problem? I can see that the file size of the PNG plugin has changed version to version, so something about it has changed. It seems as though there is something defective about the ones installed with CS2/3, and just copying the CS version into my CS3 folder clears up the problem.
    Also, the problem is not limited to my computer. Other macs that try to open PNG files from the server using CS3 or 2 also hang.

    Yes, we're a prepress company moving around probably a few dozen gb of data per day, saving PSD, TIFF, EPS, JPEG, all kinds of formats. It's the first time I've had a client requesting PNG files, and so the issue has come to light. This is the first time I've ever seen any kind of issue opening/saving across our network in 8 years. (the only time I've ever seen a corrupt file was a 1.6gb image that didn't copy correctly, and that wasn't a photoshop-related corruption, but an OS drag/copy of the file)
    I'm not sure if I'll be able to find someone with OS 10.5 or some other version to see if they cause problems. If anyone else reading this who works over a network can test a PNG open/save over their network and list their OS and Photoshop version it may help. I'm going to see if I can find some other computers to try it out on in the meantime and mention it to IT.

  • "I an creating a imagen using hue,sat and lum.I want to uses it as pattern,but i can´t to saved as png.Is it posible?"

    I think to create a ideal pattern with specific values of hue,sat,and lum.I create a VI, and i can to see diferent images when change the hue and saturation,but it can´t be saved as png,etc, with a error"invalid image"
    Attachments:
    patrondinamyc1.vi ‏92 KB

    HSL images can only be saved in the AIPD format. Please see the IMAQ Vision Concepts Manual or the LabVIEW help page for IMAQ Write File for more details. To save the image to another file format, you could convert it to RGB and then convert back to HSL when you are going to use the image later.
    Regards,
    Brent R.
    Applications Engineer
    National Instruments

  • Saving and loading images (png) on the iPhone / iPad locally

    Hi,
    you might find this helpful..
    Just tested how to save and load images, png in this case, locally on the i-Devices.
    In addition with a SharedObject it could be used as an image cache.
    Make sure you have the adobe.images.PNG encoder
    https://github.com/mikechambers/as3corelib/blob/master/src/com/adobe/images/PNGEncoder.as
    Not really tested, no error handling, just as a start.
    Let me know, what you think...
    Aaaaah and if somebody has any clue about this:
    http://forums.adobe.com/thread/793584?tstart=0
    would be great
    Cheers Peter
        import flash.display.Bitmap
         import flash.display.BitmapData
        import flash.display.Loader   
        import flash.display.LoaderInfo
        import flash.events.*
        import flash.filesystem.File
        import flash.filesystem.FileMode
        import flash.filesystem.FileStream
        import flash.utils.ByteArray;
        import com.adobe.images.PNGEncoder;
    private function savePic(){
        var bmp =  // Your Bitmap to save
        savePicToFile(bmp, "test.png")
    private function loadPic(){
         readPicFromFile("test.png")
    private function savePicToFile(bmp:Bitmap, fname:String){
           var ba:ByteArray = PNGEncoder.encode(bmp.bitmapData);
            var imagefile:File = File.applicationStorageDirectory;
            imagefile = imagefile.resolvePath(fname);
            var fileStream = new FileStream();
            fileStream.open(imagefile, FileMode.WRITE);
            fileStream.writeBytes(ba);
             trace("saved imagefile:"+imagefile.url)
    private function readPicFromFile(fname:String){
            var imagefile:File = File.applicationStorageDirectory;
            imagefile = imagefile.resolvePath(fname);
            trace("read imagefile:"+imagefile.url)
            var ba:ByteArray = new ByteArray();
            var fileStream = new FileStream();
            fileStream.open(imagefile, FileMode.READ);
            fileStream.readBytes(ba);
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onPicRead)
            loader.loadBytes(ba);   
    private function onPicRead(e:Event){
        trace("onPicRead")
         var bmp:Bitmap = Bitmap(e.target.content)
         // Do something with it

    Are the movies transferred to your iPhone via the iTunes sync/transfer process but don't play on your iPhone?
    Copied from this link.
    http://www.apple.com/iphone/specs.html
    Video formats supported: H.264 video, up to 1.5 Mbps, 640 by 480 pixels, 30 frames per second, Low-Complexity version of the H.264 Baseline Profile with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats; H.264 video, up to 2.5 Mbps, 640 by 480 pixels, 30 frames per second, Baseline Profile up to Level 3.0 with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats; MPEG-4 video, up to 2.5 Mbps, 640 by 480 pixels, 30 frames per second, Simple Profile with AAC-LC audio up to 160 Kbps, 48kHz, stereo audio in .m4v, .mp4, and .mov file formats.
    What are you using for the conversion? Does whatever you are using for the conversion include an iPod or iPhone compatible setting for the conversion?
    iTunes includes a create iPod or iPhone version for a video in your iTunes library. Select the video and at the menu bar, go to Advanced and select Create iPod or iPhone version. This will duplicate the video in your iTunes library. Select this version for transfer to your iPhone to see if this makes any difference.

  • Saved in .png formant and now need to edit, but how?

    Hi all,
    I created a logo/picture and saved it as a png, but now it seems I can edit it. Is there anyway to edit a already saved .png file created in illustrator CS4?
    Thanks,
    nyfdmkt

    If you also saved the file then you should have aversion with the .ai extension somewhere. Otherwise you have a rastered image file you have to edit in Photoshop or Fireworks. which i not what you want.
    Always save the ai file even if you are exporting to png.

  • Load, crop and saving jpg and gif images with JFileChooser

    Hello!
    I wonder is there someone out there who can help me with a applic that load, (crop) and saving images using JFileChooser with a simple GUI as possible. I'm new to programming and i hope someone can show me.
    Tor

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.filechooser.*;
    import javax.swing.filechooser.FileFilter;
    public class ChopShop extends JPanel {
        JFileChooser fileChooser;
        BufferedImage image;
        Rectangle clip = new Rectangle(50,50,150,150);
        boolean showClip = true;
        public ChopShop() {
            fileChooser = new JFileChooser(".");
            fileChooser.setFileFilter(new ImageFilter());
        public void setClip(int x, int y) {
            clip.setLocation(x, y);
            repaint();
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            if(image != null) {
                int x = (getWidth() - image.getWidth())/2;
                int y = (getHeight() - image.getHeight())/2;
                g2.drawImage(image, x, y, this);
            if(showClip) {
                g2.setPaint(Color.red);
                g2.draw(clip);
        public Dimension getPreferredSize() {
            int width = 400;
            int height = 400;
            int margin = 20;
            if(image != null) {
                width = image.getWidth() + 2*margin;
                height = image.getHeight() + 2*margin;
            return new Dimension(width, height);
        private void showOpenDialog() {
            if(fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
                File file = fileChooser.getSelectedFile();
                try {
                    image = ImageIO.read(file);
                } catch(IOException e) {
                    System.out.println("Read error for " + file.getPath() +
                                       ": " + e.getMessage());
                    image = null;
                revalidate();
                repaint();
        private void showSaveDialog() {
            if(image == null || !showClip)
                return;
            if(fileChooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
                File file = fileChooser.getSelectedFile();
                String ext = ((ImageFilter)fileChooser.getFileFilter()).getExtension(file);
                // Make sure we have an ImageWriter for this extension.
                if(!canWriteTo(ext)) {
                    System.out.println("Cannot write image to " + ext + " file.");
                    String[] formatNames = ImageIO.getWriterFormatNames();
                    System.out.println("Supported extensions are:");
                    for(int j = 0; j < formatNames.length; j++)
                        System.out.println(formatNames[j]);
                    return;
                // If file exists, warn user, confirm overwrite.
                if(file.exists()) {
                    String message = "<html>" + file.getPath() + " already exists" +
                                     "<br>Do you want to replace it?";
                    int n = JOptionPane.showConfirmDialog(this, message, "Confirm",
                                                          JOptionPane.YES_NO_OPTION);
                    if(n != JOptionPane.YES_OPTION)
                        return;
                // Get the clipped image, if available. This is a subImage
                // of image -> they share the same data. Handle with care.
                BufferedImage clipped = getClippedImage();
                if(clipped == null)
                    return;
                // Copy the clipped image for safety.
                BufferedImage cropped = copy(clipped);
                boolean success = false;
                // Write cropped to the user-selected file.
                try {
                    success = ImageIO.write(cropped, ext, file);
                } catch(IOException e) {
                    System.out.println("Write error for " + file.getPath() +
                                       ": " + e.getMessage());
                System.out.println("writing image to " + file.getPath() +
                                   " was" + (success ? "" : " not") + " successful");
        private boolean canWriteTo(String ext) {
            // Support for writing gif format is new in j2se 1.6
            String[] formatNames = ImageIO.getWriterFormatNames();
            //System.out.printf("writer formats = %s%n",
            //                   java.util.Arrays.toString(formatNames));
            for(int j = 0; j < formatNames.length; j++) {
                if(formatNames[j].equalsIgnoreCase(ext))
                    return true;
            return false;
        private BufferedImage getClippedImage() {
            int w = getWidth();
            int h = getHeight();
            int iw = image.getWidth();
            int ih = image.getHeight();
            // Find origin of centered image.
            int ix = (w - iw)/2;
            int iy = (h - ih)/2;
            // Find clip location relative to image origin.
            int x = clip.x - ix;
            int y = clip.y - iy;
            // clip must be within image bounds to continue.
            if(x < 0 || x + clip.width  > iw || y < 0 || y + clip.height > ih) {
                System.out.println("clip is outside image boundries");
                return null;
            BufferedImage subImage = null;
            try {
                subImage = image.getSubimage(x, y, clip.width, clip.height);
            } catch(RasterFormatException e) {
                System.out.println("RFE: " + e.getMessage());
            // Caution: subImage is not independent from image. Changes
            // to one will affect the other. Copying is recommended.
            return subImage;
        private BufferedImage copy(BufferedImage src) {
            int w = src.getWidth();
            int h = src.getHeight();
            BufferedImage dest = new BufferedImage(w, h, src.getType());
            Graphics2D g2 = dest.createGraphics();
            g2.drawImage(src, 0, 0, this);
            g2.dispose();
            return dest;
        private JPanel getControls() {
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridwidth = GridBagConstraints.REMAINDER;
            panel.add(getCropPanel(), gbc);
            panel.add(getImagePanel(), gbc);
            return panel;
        private JPanel getCropPanel() {
            JToggleButton toggle = new JToggleButton("clip", showClip);
            toggle.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    showClip = ((AbstractButton)e.getSource()).isSelected();
                    repaint();
            SpinnerNumberModel widthModel = new SpinnerNumberModel(150, 10, 400, 1);
            final JSpinner widthSpinner = new JSpinner(widthModel);
            SpinnerNumberModel heightModel = new SpinnerNumberModel(150, 10, 400, 1);
            final JSpinner heightSpinner = new JSpinner(heightModel);
            ChangeListener cl = new ChangeListener() {
                public void stateChanged(ChangeEvent e) {
                    JSpinner spinner = (JSpinner)e.getSource();
                    int value = ((Number)spinner.getValue()).intValue();
                    if(spinner == widthSpinner)
                        clip.width = value;
                    if(spinner == heightSpinner)
                        clip.height = value;
                    repaint();
            widthSpinner.addChangeListener(cl);
            heightSpinner.addChangeListener(cl);
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2,2,2,2);
            gbc.weightx = 1.0;
            panel.add(toggle, gbc);
            addComponents(new JLabel("width"),  widthSpinner,  panel, gbc);
            addComponents(new JLabel("height"), heightSpinner, panel, gbc);
            return panel;
        private void addComponents(Component c1, Component c2, Container c,
                                   GridBagConstraints gbc) {
            gbc.anchor = GridBagConstraints.EAST;
            c.add(c1, gbc);
            gbc.anchor = GridBagConstraints.WEST;
            c.add(c2, gbc);
        private JPanel getImagePanel() {
            final JButton open = new JButton("open");
            final JButton save = new JButton("save");
            ActionListener al = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    JButton button = (JButton)e.getSource();
                    if(button == open)
                        showOpenDialog();
                    if(button == save)
                        showSaveDialog();
            open.addActionListener(al);
            save.addActionListener(al);
            JPanel panel = new JPanel();
            panel.add(open);
            panel.add(save);
            return panel;
        public static void main(String[] args) {
            ChopShop chopShop = new ChopShop();
            ClipMover mover = new ClipMover(chopShop);
            chopShop.addMouseListener(mover);
            chopShop.addMouseMotionListener(mover);
            JFrame f = new JFrame("click inside rectangle to drag");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(new JScrollPane(chopShop));
            f.getContentPane().add(chopShop.getControls(), "Last");
            f.pack();
            f.setLocation(200,100);
            f.setVisible(true);
    class ImageFilter extends FileFilter {
        static String GIF = "gif";
        static String JPG = "jpg";
        static String PNG = "png";
        // bmp okay in j2se 1.5+
        public boolean accept(File file) {
            if(file.isDirectory())
                return true;
            String ext = getExtension(file).toLowerCase();
            if(ext.equals(GIF) || ext.equals(JPG) || ext.equals(PNG))
                return true;
            return false;
        public String getDescription() {
            return "gif, jpg, png images";
        public String getExtension(File file) {
            String s = file.getPath();
            int dot = s.lastIndexOf(".");
            return (dot != -1) ? s.substring(dot+1) : "";
    class ClipMover extends MouseInputAdapter {
        ChopShop component;
        Point offset = new Point();
        boolean dragging = false;
        public ClipMover(ChopShop cs) {
            component = cs;
        public void mousePressed(MouseEvent e) {
            Point p = e.getPoint();
            if(component.clip.contains(p)) {
                offset.x = p.x - component.clip.x;
                offset.y = p.y - component.clip.y;
                dragging = true;
        public void mouseReleased(MouseEvent e) {
            dragging = false;
        public void mouseDragged(MouseEvent e) {
            if(dragging) {
                int x = e.getX() - offset.x;
                int y = e.getY() - offset.y;
                component.setClip(x, y);
    }

  • Loading, cropping and saving jpg files in Flex

    I'm attempting to apply the code for selecting, cropping and saving image data (.jpg, .png) as shown on the web site:
    http://www.adobe.com/devnet/flash/quickstart/filereference_class_as3.html#articlecontentAd obe_numberedheader_1
    The sample application is contained within a class called Crop contained in the action script file Crop.as which begins as follows:
    package
        import com.adobe.images.JPGEncoder;
        import com.adobe.images.PNGEncoder;
        import flash.display.BitmapData;
        import flash.display.DisplayObject;
        import flash.display.DisplayObjectContainer;
        import flash.display.Loader;
        import flash.display.LoaderInfo;
        import flash.display.Sprite;
        import flash.events.Event;
        import flash.events.IOErrorEvent;
        import flash.events.MouseEvent;
        import flash.geom.Matrix;
        import flash.geom.Rectangle;
        import flash.net.FileFilter;
        import flash.net.FileReference;
        import flash.utils.ByteArray;
        public class Crop extends Sprite
    My application attempts to make use of the Crop class by including the Crop.as file:
         <mx:Script source="Crop.as"/> 
    in the Flex Component which needs it, and then calling the Crop constructor to perform the methods of the class
       var localImage:Crop = new Crop();
       localImage.Crop();
    My application does not compile. The package statement (or the curly bracket on the following line) is flagged with the error "Packages may not be nested".
    I have no idea why this should be as I cannot see any nested definitions anywhere in my application. The component includes the Crop.as file which contains the package and class definition.
    Can anyone give my some guidance as to why this error is occurring?
    Any help would be greatly appreciated.  

    Hi Scott,
    #1
    that error is because "fx:Script" (or mx:Script) are intended to include part of Actionscript code - but not class defitions or blocks.
    So if you are trying to include e.g. such class:
    package
         import flash.display.Sprite;
         public class Crop extends Sprite
              public function Crop()
                   super();
              public function processImage():void
                   trace("processImage()");
    compiler will immediately complain as you are trying to incorporate nested class within your application code.
    #2
    here is correct way (I think) to incorporate some class via mxml tags (here using fx:Script):
    Using class sample above:
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                      xmlns:s="library://ns.adobe.com/flex/spark"
                      xmlns:mx="library://ns.adobe.com/flex/mx"
                      xmlns:utils="*"
                      applicationComplete="completeHandler(event)">
         <!-- util Crop will be initialized here as instance "cropUtil" -->
         <fx:Declarations>
              <utils:Crop id="cropUtil"/>
         </fx:Declarations>
         <!-- script where "cropUtil" will be used -->
         <fx:Script>
              <![CDATA[
                   import mx.events.FlexEvent;
                   protected function completeHandler(event:FlexEvent):void
                        cropUtil.processImage();
              ]]>
         </fx:Script>
    </s:Application>
    But note that you could simply create instance of your class by direct import in fx:Script:
         <fx:Script>
              <![CDATA[
                   import mx.events.FlexEvent;
                   private var cropUtil:Crop = null;
                   protected function completeHandler(event:FlexEvent):void
                        cropUtil = new Crop();
                        cropUtil.processImage();
              ]]>
         </fx:Script>
    hth,
    kind regards,
    Peter Blazejewicz

  • Script for saving/replacing .png´s

    For Photoshop CS5:
    Hi,
    I need a script, which allows me to take the .png file i am working on, and save and replace it in the existing location with the exact same name:
    Without creating the "copy.png" string and preferebly without have to choose "Interlaced" or "None".
    That would be a huge time saver!

    What kind of png – png8 or png24?
    Save for Web or Save as?
    I suppose one might be able to get that information from the file, but it would be easier if one could omit that and just assume one kind of saving process for all files.
    And if you do Layers stuff that can not be saved as png you would nonetheless be asked whether to save the layered file on closing, I guess.

  • Question about "Get Web Drawing URL and Page Name From" for Visio Web Access

    I am trying to get both the web drawing URL and the page name from a list through Share Point Designer 2013, but it doesn´t work.
    It looks fine when a do the web part connection wizard. I select from which columns to get the URL and the page name. But on the final web part page nothing happens. It just shows the URL that is selected in the Visio Web Access Web part. I had hoped that
    that value should be overrided by the SPD-settings.
    I have googled for hours..

    Hello,
    I have now saved the Visio-file in .vdw-format, but it says Visio 2010 Web Drawing (*.vdw). Is there a .vdw-format for 2013? Isn´t that the .vsdx-format?
    Still doesn´t work with the .vdw-format, but maybe I am doing something wrong.
    Any ideas?

  • Saving a .PNG in Photoshop CS6

    by the way in PS how do we save something as a .png file these days? it is not listed in the save as options anymore?
    Kind Regards
    David Fellows

    David,
    Check your Save As... dialog box again. You should have an option for PNG in the file type drop-down menu.
    Additionally, you can choose File > Save for Web and you will have an option for saving a PNG!
    I hope this helps you out!
    Michael

  • I've created a "header" in Illustrator. When I send it to someone to be used in a report.. it comes up "blurred" or, with a white background. I tried opening in Photoshop and saving as JPEG, but get same results. What do I do?

    Can anyone give me suggestions .. after creating a "logo" or a "header" to be used by someone else in a presentation or report.. I can't figure out how to make the background transparent, and keep the image clear. Created in CS6 Illustrator.. tried opening in Photoshop and saving as JPEG.. no luck.

    Have you tried exporting for MS Office?
    You could also try exporting as transparent PNG with 144 ppi.
    On top of that: don't scale it in Office.

  • Draw lines and columns button was disabled

    hi friends,
    in my smartform template draw lines and columns button was disabled which results select pattern button also disabled. now i am unable to change any lines, can any one help me how to enable this button to change.
    thanks and regards,
    venkat suman.

    Hi
    I come to the same problem and google lead me here.
    Not the problem of Display/Change mode or authorization.
    I fix this problem as below:
    1) create a new smartform and create a template
    2) click the "Settings" button
    3) in tab General, check the "Draw Lines and Columns", click OK
    4) exit without saving
    5) now I can use the "Draw Lines and Columns" button
    but here when I click the Settings button again, the "Draw Lines and Columns" is unchecked.
    Hope this can help
    May some mentor give an explanation.

  • I need help to find and open a job app that I exported, was able to fill out and sign and saved and now can't open it? What did I do wrong?

    I need help to find and open a job app that I exported, was able to fill out and sign and saved and now can't open it? What did I do wrong?

    What file format did you export it to?

  • Saving NSDatePicker to a string and saving that to NSUserDefaults...

    Saving NSDatePicker to a string and saving that to NSUserDefaults I have it saved to a string then I have code that should save it to NSUSerDefaults so that when the program starts it is saved as the string not null. Here is the code [CODE]#import "MainView.h"
    #import "DateView.h"
    @implementation MainView
    -(void)awakeFromNib
    [self removeFromSuperview];
    [self addSubview:dateView];
    [dateView setdateandtime];
    [dateView permsavedattime];
    @end [/CODE] [CODE]#import "DateView.h"
    #include "MainView.h"//Use #import this is to see if #include Works
    @implementation DateView
    -(IBAction)showuserdefaultdate
    [self userdefaultdate];
    //dateoutput.text =tddate;
    -(void)permsavedattime
    tddate=[prefs stringForKey:@"testing"];
    tdtime=[prefs stringForKey:@"timetesting"];
    dateoutput.text =[[NSString alloc] initWithFormat:@"%@",tddate];
    -(void)userdefaultdate
    prefs =[NSUserDefaults standardUserDefaults];
    [prefs setInteger:tddate forKey:@"testing"];
    [prefs setObject:tdtime forKey:@"timetesting"];
    -(void)setdateandtime
    [Today setDate:[NSDate date] animated:YES];
    //formatting date style
    dateformatter = [ [ NSDateFormatter alloc ] init ];
    [ dateformatter setDateStyle:NSDateFormatterLongStyle];
    [ dateformatter setTimeStyle:NSDateFormatterNoStyle ];//makes it so the time is not included
    //[ formatter setTimeStyle:NSDateFormatterLongStyle ];//set to anystyle besides
    //NoStyle if you dont want time included.
    [Time setDate:[NSDate date] animated:YES];
    //formatting date style
    timeformatter = [ [ NSDateFormatter alloc ] init ];
    [ timeformatter setDateStyle:NSDateFormatterNoStyle];//makes it so it doesn't get the date
    [ timeformatter setTimeStyle:NSDateFormatterShortStyle];//makes it so the time is just hour and minute and A.M. or P.M.
    //[ formatter setTimeStyle:NSDateFormatterLongStyle ];//set to anystyle besides
    //NoStyle if you dont want time included.
    -(IBAction)recieveDate
    tddate= [dateformatter stringFromDate:Today.date];//Asigning the date to the string
    dateoutput.text =tddate;
    -(IBAction)recievetime
    tdtime= [timeformatter stringFromDate:Time.date];//Asigning the date to the string
    timeoutput.text =tdtime;
    -(IBAction)canceltime
    [Time setDate:[NSDate date] animated:YES];
    tdtime= [timeformatter stringFromDate:Time.date];//Asigning the date to the string
    timeoutput.text =tdtime;
    -(IBAction)canceldate
    [Today setDate:[NSDate date] animated:YES];
    tddate= [dateformatter stringFromDate:Today.date];//Asigning the date to the string
    dateoutput.text =tddate;
    @end[/CODE] What am I missing? It keeps coming up Null I need it saved right so I can send it through email

    softwarespecial wrote:
    why can't I have the prefs saved in the .h
    You can save that address in an ivar if you want to, but there's no purpose to that. The standardUserDefaults object is a +shared class object+. It's like a dictionary object that's maintained for your program by the NSUserPreferences class. You can read from or write to it at any time for the duration of your program. So whenever you get the shared object's address [NSUserDefaults standardUserDefaults], you're just getting the address of that same object each time.
    In case the above doesn't make sense, I ran across a good explanation by Danneman in the last message on this page: [http://www.iphonedevsdk.com/forum/iphone-sdk-development/18716-set-settings-va riable-code.html].
    When I did that as you so wisely pointed out it didn't work but when I saved it at each point I needed it it works.
    When you change two things at once it's easy to forget the first and assume the second change solved the problem. Actually, I don't think saving prefs in your ivar had anything to do with your bug. What fixed it was getting a pointer to the shared std defaults object in this method:
    -(void)permsavedattime
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; <-- get the shared object
    tddate=[prefs stringForKey:@"testing"];
    tdtime=[prefs stringForKey:@"timetesting"];
    dateoutput.text =[[NSString alloc] initWithFormat:@"%@",tddate];
    Without the first line of the above, I'm fairly sure that your prefs ivar was nil. I didn't see any code that initialized that ivar prior to the first time userdefaultdate ran. It looked to me like permsavedattime ran at start up, well before prefs was set in userdefaultdate. If you're interested in backtracking, restore the file to the way it was when you posted, then add a NSLog() like this:
    -(void)permsavedattime
    // NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults]; <-- get the shared object
    NSLog(@"prefs=%@", prefs);
    tddate=[prefs stringForKey:@"testing"];
    tdtime=[prefs stringForKey:@"timetesting"];
    dateoutput.text =[[NSString alloc] initWithFormat:@"%@",tddate];
    I wish to save lets say five different things to NSUSerDefaults would I be able to do it all with my NSUserDefaults prefs or would I have to create a another one for some of them?
    You know the answer to your second question now, right? The important point is that you're never creating the shared object, you're just asking for its address whenever you need it.
    Btw, there's another user defaults method you should know about: The synchronize method writes the data to disk. You might want to do that when your app is ready to exit. E.g., in the app delegate:
    - (void)applicationWillTerminate:(UIApplication *)application {
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    [prefs synchronize];
    Although the docs suggest synchronize when the app is about to exit, I'm not sure it's necessary. I think the system might write the defaults out to disk anyway when the app terminates, but not sure about this. +User Defaults Programming Topics for Cocoa+ says:
    On Mac OS X v10.5 and later, in applications in which a run-loop is present, synchronize is automatically invoked at periodic intervals. Consequently, you might synchronize before exiting a process, but otherwise you shouldn’t need to.
    The above is in the iPhone edition, so I think it applies.
    It might also be a good idea to update the data and call resetStandardUserDefaults in didReceiveMemoryWarning. I'm not clear about the need for reset either though, since the system may do that for you as well. But on a memory warning, you would definitely want to update the user default data if some of it is stored in an object to be released. You can find out how your app behaves on a memory warning by selecting Hardware->Simulate Memory Warning from the iPhone Simulator menu.
    - Ray

Maybe you are looking for

  • Enhanced protected mode and global named shared memory object

    Good morning. I've written a bho that do data exchange with a system service. The service creates named shared memory objects in the Global namespace. Outside appcontainer IE 11 sandboxed everything works fine lowering objects integrity level. Inside

  • SAX parser not finding my DTD. Help please

    I have written a small XML file and its DTD that are stored in the same folder which is C:/Work/pdftools. Here is a part of the code that is generating errors: inputSource.setSystemId( "c:/Work/pdftools/userSettings.xml" ); parserAdapter.parse( input

  • When executed on unix, it throws file not found error

    Hi, Can anybody please let me know what I am doing wrong. The code works fine on windows box and fails on unix box. import java.io.*; import org.apache.axis.encoding.Base64; public class writeToFile {     public static void main(String args[]){     t

  • Whats the use  of function module RSAP_IDOC_SEND?

    Hi Gurus, Can anyone please let me know the use of Function Module - RSAP_IDOC_SEND. Regards Avi....

  • Transfer auf anderen Rechner

    Hallo, ich würde gerne meine Adobe Master Collection CS5.5 in Kürze auf einen anderen Rechner transferieren, da mein akuteller Rechner nicht mehr richtig funktioniert. Ich besitze die Schüler und Studentenversion, deshalb bin ich mir nicht sicher ob