Image Resizing and Folio Renditions
Hello!
I'm building a pretty large app, and I'm concerned about the size of some of my larger images.
A. Is it typical to build both 1024x768 and 2048x1536 renditions? Or should I just build the 1024x768 and size my full page images for the 2048x1536? Or will it automatically view them at 72dpi?
B. If I do build both renditions, can I keep the two different layouts in the same file with alternate layout? Or would I have to build a separate folio like I would for the iPhone?
C. What is the best format to save images in? I've always saved as jpgs, but if I'm able to save as a gif or png for file size, I'd prefer to do that. But I don't want to compromise the integrity of the photo either.
Thank you!
Depending on the format of your files, you need not go into JAI. You may be able to do what you want with ImageIO.
You just need to load the image, select the part you want, then check the length to width ratio to make sure it is appropriate, if not, then adjust it as such.
If you want to get a 100, 100 thumb from a 1024, 768 image you can do this:
BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
g.drawImage(my1024x768, 0, 12, 100, 75, Color.BLACK, null);
g.dispose();please note, that to get 1024 shunk up to 100, you need to divide by 10.24, when you do the same to the height of the image, you get 75, this leaves 25 pixels--so I centered the image at 12.
to save the thumb in JPG:
File f = new File(myFileNameAndPath);
f.createFile();
ImageIO.write(bi, "JPEG", f);**WARNING** untested code.
Similar Messages
-
PHP -Mysql image resize and upload
All,
Any good ideas, code out there to help me do a PHP MySQL image resize, uploade and display? Thanks for your help!For upload image, u may look at the similar thread HERE
-
Hi,
I want to convert images to thumbnails with a 'standard' format - I need all images to have the same width and height.
So I need to resize and then crop the images. Is this possibe with JAI? Are there other libraries which can do this better?
I've read about ImageMagick - are the Java interfaces to ImageMagick good?
/regards, Håkan JacobssonDepending on the format of your files, you need not go into JAI. You may be able to do what you want with ImageIO.
You just need to load the image, select the part you want, then check the length to width ratio to make sure it is appropriate, if not, then adjust it as such.
If you want to get a 100, 100 thumb from a 1024, 768 image you can do this:
BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
g.drawImage(my1024x768, 0, 12, 100, 75, Color.BLACK, null);
g.dispose();please note, that to get 1024 shunk up to 100, you need to divide by 10.24, when you do the same to the height of the image, you get 75, this leaves 25 pixels--so I centered the image at 12.
to save the thumb in JPG:
File f = new File(myFileNameAndPath);
f.createFile();
ImageIO.write(bi, "JPEG", f);**WARNING** untested code. -
I am new to Flex, and I have (so far) only developed two
other applications using Flex.
I am having a really difficult time with this issue. I've
tried everything (except for creating a class) that I can think of
to resolve this issue, and I'm running out of ideas.
What I am trying to do is create an AIR application that
takes the selected images and resizes them to a specified maximum
height and width. It is resizing the image and saving it in a
temporary spot, but it will not upload after it saves it. I keep
receiving the error below:
quote:
Error #2044: Unhandled IOErrorEvent:. text=Error #2038: File
I/O Error.
at flash.filesystem::File/resolveComponents()
at flash.filesystem::File/resolvePath()
at ImageUploader/saveAndUploadImage()[C:\Documents and
Settings\jgosselin\workspace\ImageUploader\src\ImageUploader.mxml:136]
at ImageUploader/uploadButton_click()[C:\Documents and
Settings\jgosselin\workspace\ImageUploader\src\ImageUploader.mxml:50]
at ImageUploader/__uploadButton_click()[C:\Documents and
Settings\jgosselin\workspace\ImageUploader\src\ImageUploader.mxml:213]
My guess is that there is a lock on the file while it is
being written and it tries to upload it before it closes. However,
(as shown in the code) that is not the case. The error references
to lines that has nothing to do with the line of code that is
causing the issue. I have stepped through the code and it stops
after the FileStream close event handler has been executed. What am
I missing? What is it that I am not seeing? Has anyone developed
something similar to this application? As shown in the code, I am
using a series of events that triggers the next step of the
process.
EDIT: The code below is a scaled-down version of the
application.Here is the code:
quote:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="
http://www.adobe.com/2006/mxml"
xmlns:local="SmoothImage.as" layout="vertical" horizontalGap="0"
verticalGap="0" paddingLeft="8" paddingRight="8" paddingTop="8"
paddingBottom="8" width="640" height="480" xmlns:local1="*">
<mx:Script>
<![CDATA[
import flash.events.OutputProgressEvent;
import flash.events.ProgressEvent;
import flash.filesystem.File;
import flash.filesystem.FileStream;
import flash.net.FileReference;
import flash.net.URLRequest;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.graphics.codec.JPEGEncoder;
[Bindable] private var filesFiltered:Array;
private var maxImageWidth:Number = 640;
private var maxImageHeight:Number = 480;
private var tempFile:Array;
private var currentFile:Number;
private function uploadButton_click(event:Event):void
tempFile = fileThumb.selectedItems;
currentFile = 0;
saveAndUploadImage(tempFile[currentFile]);
private function
uploadFile_progress(event:ProgressEvent):void
var bytesUploaded:Number = event.bytesLoaded;
var bytesTotal:Number = event.bytesTotal;
uploadProgress.setProgress(bytesUploaded, bytesTotal);
uploadProgress.label = "Uploaded: " +
Math.round((bytesUploaded / bytesTotal) * 100) + "%";
private function uploadFile_complete(event:Event):void
uploadProgress.setProgress(0, 1);
uploadProgress.label = "";
if (currentFile + 1 < tempFile.length)
currentFile++;
saveAndUploadImage(tempFile[currentFile]);
private function
newFileStream_progress(event:OutputProgressEvent):void
var bytesPending:Number = event.bytesPending;
var bytesTotal:Number = event.bytesTotal;
var percentage:Number = Math.round(100 - ((bytesPending /
bytesTotal) * 100));
uploadProgress.setProgress(percentage, 100);
uploadProgress.label = "Writing: " + percentage + "%";
if (bytesPending == 0) { event.target.close(); }
private function newFileStream_close(event:Event):void
var uploadURL:URLRequest = new URLRequest("
http://localhost:8080/customers/propertypanorama_com/fileupload.php");
var uploadFile:FileReference =
FileReference(tempFile[currentFile]);
uploadFile.addEventListener(ProgressEvent.PROGRESS,
uploadFile_progress);
uploadFile.addEventListener(Event.COMPLETE,
uploadFile_complete);
uploadFile.upload(uploadURL, "uploadFile");
uploadProgress.setProgress(0, 1);
uploadProgress.label = "";
private function loader_complete(event:Event):void
var loader:Loader = Loader(event.target.loader);
var originalWidth:Number = event.target.width;
var originalHeight:Number = event.target.height;
var originalBitmap:BitmapData = new
BitmapData(originalWidth, originalHeight, false, 0x000000);
originalBitmap.draw(loader.content, null, null, null, null,
true);
var newImage:BitmapData = resizeImage(originalBitmap);
var newFileStream:FileStream = new FileStream();
newFileStream.addEventListener(OutputProgressEvent.OUTPUT_PROGRESS,
newFileStream_progress);
newFileStream.addEventListener(Event.CLOSE,
newFileStream_close);
newFileStream.openAsync(tempFile[currentFile],
FileMode.WRITE);
var jpgEncode:JPEGEncoder = new JPEGEncoder();
var writeData:ByteArray = jpgEncode.encode(newImage);
newFileStream.writeBytes(writeData, 0, writeData.length);
private function saveAndUploadImage(originalImage:File):void
var fromOldExt:String = originalImage.name;
var toJPG:String;
if (originalImage.extension.length == 4)
toJPG = fromOldExt.substring(0, fromOldExt.length - 4) +
"jpg";
else
toJPG = fromOldExt.substring(0, fromOldExt.length - 3) +
"jpg";
tempFile[currentFile] =
File.applicationStorageDirectory.resolvePath(toJPG);
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
loader_complete);
loader.load(new URLRequest(originalImage.nativePath));
private function
resizeImage(originalImage:BitmapData):BitmapData
var originalWidth:Number = originalImage.width;
var originalHeight:Number = originalImage.height;
var doResize:Boolean = false;
var scaleRatio:Number = 1;
var newImageMatrix:Matrix;
var newImage:BitmapData;
var newWidth:Number = 0;
var newHeight:Number = 0;
doResize = (originalWidth > maxImageWidth ||
originalHeight > maxImageHeight);
if (doResize)
if (originalWidth > maxImageWidth)
scaleRatio = maxImageWidth / originalWidth;
newWidth = originalWidth * scaleRatio;
newHeight = originalHeight * scaleRatio;
else
scaleRatio = maxImageHeight / originalHeight;
newWidth = originalWidth * scaleRatio;
newHeight = originalHeight * scaleRatio;
newImageMatrix = new Matrix();
newImageMatrix.scale(scaleRatio, scaleRatio);
newImage = new BitmapData(newWidth, newHeight, false,
0x000000);
newImage.draw(originalImage, newImageMatrix, null, null,
null, true);
newImageMatrix = null;
return newImage;
else
return originalImage;
]]>
</mx:Script>
<mx:HBox width="100%" horizontalAlign="right"
paddingLeft="2" paddingRight="2" paddingTop="2" paddingBottom="2"
verticalAlign="middle">
<mx:ProgressBar id="uploadProgress" label="" width="100%"
/>
<mx:Button id="uploadButton" label="Upload"
click="uploadButton_click(event);" />
</mx:HBox>
</mx:WindowedApplication> -
Hi guys,
I've been checking around the net for a way to implement the following:
user wants to upload a large image. the image is resized locally on their computer to a 60kb small image. this image is then uploaded and used.
Is there a way to do this with flash? or what is the best method? (NB: I'm not interested in using Java)
thanks for any info or links.
JeffWell in short, you need a second language to support that,
e.g. PHP/ASP/CF.
First you'll have to build a GUi in which you can upload the
jpg, putting it to the server using php/asp/cf, then you'll need to
make a call to that image, (importing it into your flex), then
you'll have to set the parameters for the resizing, then you'll
have to call a php/asp/cf script which does te resizing -
Images resized and exif stripped when emailed ?
Does any know why the iPhone resizes images (to 640x480) and strips out EXIF data when you email a photo. However, if you download the photos you get the full size and EXIF data ?
As i often like to email photos direct to Flickr from my iphone it is very annoying to end up with a poorer image than what i should have.Hello All,
Great news for the Apple iPhone.
Just downloaded 2.1 software update, and the Geotagging correctly geotags the southern hemisphere, now adds a GPS Time-Stamp as well as the GPS longitude & latitude info to the EXIF.
AND, when you e-mail it or transmit the image to a secure server, mobleme, Flickr . . . ALLL OF THE EXIF DATA STAYS INTACT, INCLUDING THE GPS METATAGS . . .
AND THE SIZE OF THE IMAGE HAS BEEN REDUCED FROM 1200 X 1600 TO 600 X 800 . . . -
Image resizing and interpolation plugin
A friend reports that genuine factals plugin is a part of Photoshop CS3. I note that a plugin for Photoshop (version not given) is advertised for sale by OnOneSoftware.
Any comments appreciated.The GF plug-in is not part of Photoshop, you buy it from OnOne Software.
John -
Why won't Photoshop revert to earlier history state after image resize when scripted?
I've written an Applescript to automate watermarking and resizing images for my company. Everything generally works fine — the script saves the initial history state to a variable, resizes the image, adds the appropriate watermark, saves off a jpeg, then reverts to the initial history state for another resize and watermark loop.
The problem is when I try not to use a watermark and only resize by setting the variable `wmColor` to `"None"` or `"None for all"`. It seems that after resizing and saving off a jpeg, Photoshop doesn't like it when I try to revert to the initial history state. This is super annoying, since clearly a resize should count as a history step, and I don't want to rewrite the script to implement multiple open/close operations on the original file. Does anyone know what might be going on? This is the line that's generating the problem (it's in both the doBig and doSmall methods, and throws an error every time I ask it just to do an image resize and change current history state):
set current history state of current document to initialState
and here's the whole script:
property type_list : {"JPEG", "TIFF", "PNGf", "8BPS", "BMPf", "GIFf", "PDF ", "PICT"}
property extension_list : {"jpg", "jpeg", "tif", "tiff", "png", "psd", "bmp", "gif", "jp2", "pdf", "pict", "pct", "sgi", "tga"}
property typeIDs_list : {"public.jpeg", "public.tiff", "public.png", "com.adobe.photoshop-image", "com.microsoft.bmp", "com.compuserve.gif", "public.jpeg-2000", "com.adobe.pdf", "com.apple.pict", "com.sgi.sgi-image", "com.truevision.tga-image"}
global myFolder
global wmYN
global wmColor
global nameUse
global rootName
global nameCount
property myFolder : ""
-- This droplet processes files dropped onto the applet
on open these_items
-- FILTER THE DRAGGED-ON ITEMS BY CHECKING THEIR PROPERTIES AGAINST THE LISTS ABOVE
set wmColor to null
set nameCount to 0
set nameUse to null
if myFolder is not "" then
set myFolder to choose folder with prompt "Choose where to put your finished images" default location myFolder -- where you're going to store the jpgs
else
set myFolder to choose folder with prompt "Choose where to put your finished images" default location (path to desktop)
end if
repeat with i from 1 to the count of these_items
set totalFiles to count of these_items
set this_item to item i of these_items
set the item_info to info for this_item without size
if folder of the item_info is true then
process_folder(this_item)
else
try
set this_extension to the name extension of item_info
on error
set this_extension to ""
end try
try
set this_filetype to the file type of item_info
on error
set this_filetype to ""
end try
try
set this_typeID to the type identifier of item_info
on error
set this_typeID to ""
end try
if (folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the type_list) or (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then
-- THE ITEM IS AN IMAGE FILE AND CAN BE PROCESSED
process_item(this_item)
end if
end if
end repeat
end open
-- this sub-routine processes folders
on process_folder(this_folder)
set these_items to list folder this_folder without invisibles
repeat with i from 1 to the count of these_items
set this_item to alias ((this_folder as Unicode text) & (item i of these_items))
set the item_info to info for this_item without size
if folder of the item_info is true then
process_folder(this_item)
else
try
set this_extension to the name extension of item_info
on error
set this_extension to ""
end try
try
set this_filetype to the file type of item_info
on error
set this_filetype to ""
end try
try
set this_typeID to the type identifier of item_info
on error
set this_typeID to ""
end try
if (folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the type_list) or (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then
-- THE ITEM IS AN IMAGE FILE AND CAN BE PROCESSED
process_item(this_item)
end if
end if
end repeat
end process_folder
-- this sub-routine processes files
on process_item(this_item)
set this_image to this_item as text
tell application id "com.adobe.photoshop"
set saveUnits to ruler units of settings
set display dialogs to never
open file this_image
if wmColor is not in {"None for all", "White for all", "Black for all"} then
set wmColor to choose from list {"None", "None for all", "Black", "Black for all", "White", "White for all"} with prompt "What color should the watermark be?" default items "White for all" without multiple selections allowed and empty selection allowed
end if
if wmColor is false then
error number -128
end if
if nameUse is not "Just increment this for all" then
set nameBox to display dialog "What should I call these things?" default answer ("image") with title "Choose the name stem for your images" buttons {"Cancel", "Just increment this for all", "OK"} default button "Just increment this for all"
set nameUse to button returned of nameBox -- this will determine whether or not to increment stem names
set rootName to text returned of nameBox -- this will be the root part of all of your file names
set currentName to rootName
else
set nameCount to nameCount + 1
set currentName to rootName & (nameCount as text)
end if
set thisDocument to current document
set initialState to current history state of thisDocument
set ruler units of settings to pixel units
end tell
DoSmall(thisDocument, currentName, initialState)
DoBig(thisDocument, currentName, initialState)
tell application id "com.adobe.photoshop"
close thisDocument without saving
set ruler units of settings to saveUnits
end tell
end process_item
to DoSmall(thisDocument, currentName, initialState)
tell application id "com.adobe.photoshop"
set initWidth to width of thisDocument
if initWidth < 640 then
resize image thisDocument width 640 resample method bicubic smoother
else if initWidth > 640 then
resize image thisDocument width 640 resample method bicubic sharper
end if
set myHeight to height of thisDocument
set myWidth to width of thisDocument
if wmColor is in {"White", "White for all"} then
set wmFile to (path to resource "water_250_white.png" in bundle path to me) as text
else if wmColor is in {"Black", "Black for all"} then
set wmFile to (path to resource "water_250_black.png" in bundle path to me) as text
end if
if wmColor is not in {"None", "None for all"} then
open file wmFile
set wmDocument to current document
set wmHeight to height of wmDocument
set wmWidth to width of wmDocument
duplicate current layer of wmDocument to thisDocument
close wmDocument without saving
translate current layer of thisDocument delta x (myWidth - wmWidth - 10) delta y (myHeight - wmHeight - 10)
set opacity of current layer of thisDocument to 20
end if
set myPath to (myFolder as text) & (currentName) & "_640"
set myOptions to {class:JPEG save options, embed color profile:false, quality:12}
save thisDocument as JPEG in file myPath with options myOptions appending lowercase extension
set current history state of current document to initialState
end tell
end DoSmall
to DoBig(thisDocument, currentName, initialState)
tell application id "com.adobe.photoshop"
set initWidth to width of thisDocument
if initWidth < 1020 then
resize image thisDocument width 1020 resample method bicubic smoother
else if initWidth > 1020 then
resize image thisDocument width 1020 resample method bicubic sharper
end if
set myHeight to height of thisDocument
set myWidth to width of thisDocument
if wmColor is in {"White", "White for all"} then
set wmFile to (path to resource "water_400_white.png" in bundle path to me) as text
else if wmColor is in {"Black", "Black for all"} then
set wmFile to (path to resource "water_400_black.png" in bundle path to me) as text
end if
if wmColor is not in {"None", "None for all"} then
open file wmFile
set wmDocument to current document
set wmHeight to height of wmDocument
set wmWidth to width of wmDocument
duplicate current layer of wmDocument to thisDocument
close wmDocument without saving
translate current layer of thisDocument delta x (myWidth - wmWidth - 16) delta y (myHeight - wmHeight - 16)
set opacity of current layer of thisDocument to 20
end if
set myPath to (myFolder as text) & (currentName) & "_1020"
set myOptions to {class:JPEG save options, embed color profile:false, quality:12}
save thisDocument as JPEG in file myPath with options myOptions appending lowercase extension
set current history state of current document to initialState
end tell
end DoBigAs many others here I use JavaScript so I can’t really help you with your problem.
But I’d like to point to »the lazy person’s out« – with many operations that result in creating a new file on disk I simply duplicate the image (and flatten in the same step) to minimize any chance of damaging the original file if the Script should not perform as expected. -
PSE5 Process Multiple Files Image Resize
I want to batch convert some TIFF files to JPG and make them all 300 ppi. I tried suing the Multiple file processor in the Editor just entering 300 in resolution and leaving width & height blank. I hoped it would perform the same process as going to image resize and and changing resolution with resample and constrain proportions turned off. Instead it has changed the ppi from 72 to 300, but kept the size the same i.e. has added lots of extra pixels making the file enormous.
The only way I can force it to shrink the image is to enter say 30cm as the width. The problem with this is twofold a) I have to trun all my photos so they are landscape b) if I have cropped a photo such that it doesn't have enough pixels to stretch then again it is getting resampled.
Is this a limitation of PSE5 that wouldn't be there in CS3 or am I doing something wrong? I only want to print tham out 15x10 but read I should resize everything to 300 ppi. To be honest I never did this before I had PSE and they seemed to come out OK from a Canon that saves the files as default 72 ppi but large dimensions. Maybe someone couldexplain in laymans terms why the photos need to be resized to 300 ppi anyway? Thank youWell, you see, Process Multiple files is doing just what you asked it to do: it's
resizing the photos. But you don't really want to resize the photos, just change the ppi setting. Is there a particular reason you want them to be 300ppi? PPI is a setting that only matters for printing or if you are sending a photo somewhere that requires that marker to be set to 300. Your camera doesn't know anything about ppi, only absolute pixel dimensions (eg 2480 x 1795 or whatever).
When you go to print, however, your printer may prefer to have a higher pixel density, since it can play your pixels like an accordian: squash them closer together or spread them out thinner, depending on that ppi marker. The pixel density determines the inch/cm size of your print (at 72 ppi you'll get a print that's hugely bigger but less detailed; at 300 ppi a crisper smaller print.)
I'm wondering why you would want to batch convert a whole big bunch of images at once, though. It would help if you would explain just what you want to do with the photos that requires the 300 ppi. -
Resize and Resample in Photoshop CC
Hi.
I use Photoshop since 1997 and jump from CS5 to CC this week. What I used to do sometimes is taking a 150dpi image and need to make it 72dpi, BUT I really want it to change pixels dimension. In PS CS5 I just needed to go to "Image Resize" and change 150 do 72dpi, and PS kept the Cm/Inches dimensions but changed pixels. Is exactly what I need to do. I PS CC it doesn't work, if I change dpi it will only change image size in Cm/Inches.
And example, I have an Illustrator file, 800x800px. I export it as 150dpi JPG, opens in PS. It will show an image like 1667x1667px 150dpi. I want to change it to 72dpi so my JPG will be 800x800px again.
Some people will say: "but why don't you already export from ILL as 72dpi?". Because I sometimes need those images in 150 and sometimes in 72. So I prefer to have a 150dpi image and resize to 72 if I need instead the opposite.
Do you know if there is a way in PS CC to solve it?
Thanks,
LuizDPI PPI and an image's DPI resolution setting and Inkjet Printers DPI Resolution setting ???
Dots Per Inch is an old printers term that came about when images were printed black and white using little dots of inks fined dots finer sharper images it density of dots size of dots image like news papers. Later color image usinf 4 colors CMYK...
Pixels Per Inch a term use about displays color pixels are three color Red Green Blue their geometry layout varies and some have even added a fourth yellow component again its a density size display are manufactured with a single PPI density. Different displays panels have their manufactured PPI. Most desktop LCD panels today have a ppi around 100. Displays do not support your Image Files DPI resolution setting the display pixels their PPI size. Image sizing on displays is done by scaling the numbers of pixels in a image a displaying the scaled image not the actual images pixel. Zooming percent....
Inkjets printers do not print like news papers and the do not use a single drop or dot of ink per image pixel. The user their higher finer drops of ink to paint in you images larger square pixels. You inkjet printer can print pixels and siy up to the maximum resolution. Your printer DPI setting is a quality setting the higher the setting the finer the pixels will be painted in. Higher quality settings are only available on high quality Photo paper for more ink is laid down and requires a special surface to prevent ink running pixels together regular paper would receive to much ink and be more a blotter paper.
Image DPI setting defines/sets the image Pixel size without changing a single pixel in am image you can print the image any size you want by changing the size of its pixels. -
Image select, resize and locally store (flex3 air example)
Hi there,
After a few days of struggling with images, resize functions
and file dialog boxes I created a nice example application that
shows how you can select an image, resize it and save the resized
image in the application storing directory.
I hope you can profit from it.
Greets, jacob
example code for flex 3 air.
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
import mx.graphics.codec.PNGEncoder;
public var imageFile:File;
public var fileresultimage:Object;
public var fileresultlabel:Object;
// File.applicationStorageDirectory gets you to the local
storage dir
//On Windows, this is the "projectname" directory
//(for example, C:\Documents and Settings\application
data\projectname).
// On Mac OS, it is /Users/userName/Documents.
public var docsDir:File = File.applicationStorageDirectory;
public function
imageFileDialog(image:Object,label:Object):void
fileresultimage=image;
fileresultlabel=label;
var imagesFilter:FileFilter =
new FileFilter("Foto (*.jpg, *.gif, *.png)",
"*.jpg;*.gif;*.png");
if(imageFile==null)
imageFile = new File();
imageFile.addEventListener(Event.SELECT, imageSelected);
imageFile.browseForOpen("Select an Image",[imagesFilter]);
// if there is a file selected
public function imageSelected(event:Event):void
var newFile:File = event.target as File;
//if there is a file object on the screen
if(fileresultimage!=null)
fileresultimage.source=imageFile.url;
//if there is a label object on the screen
if(fileresultlabel!=null)
fileresultlabel.text=imageFile.url;
if (newFile.exists==true)
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
handleImageComplete);
loader.load(new URLRequest(imageFile.url));
// when load of the selected image is complete we save a
smaller version of it.
public function handleImageComplete(event:Event):void
var loader:Loader = Loader(event.target.loader);
// width and heigt of selected image
var originalimgwidth:Number=event.target.width;
var originalimgheight:Number=event.target.height;
//put original image into bitmapdata
var bitmapje:BitmapData;
bitmapje=new BitmapData(originalimgwidth, originalimgheight,
true, 0x00000000);
//bitmapje.draw(loaderInfo.loader.content,null,null,null,null,true);//null
object reference
bitmapje.draw(loader.content,null,null,null,null,true);
// call the resize function and give the original
image,maxx,and maxy with it.
var thumb:BitmapData=resizeimage(bitmapje,150,150);
var newimagefile:File=new File();
// T = Thumbnail
// 1 = next id in the db
// for now we use a random number
var random:Number= Math.random();
random = Math.ceil(random*100);// to get a positive number
var filenameForSave:String="T"+random; //new filename;
newimagefile=docsDir.resolvePath("Thumbs/" + filenameForSave
+ ".png"); //image path
var stream:FileStream = new FileStream; // create new
filestream
stream.open(newimagefile, FileMode.WRITE); // open
filestream
var data:ByteArray = encodeToPng(thumb); // convert
bitmapdata to a png bytearry
stream.writeBytes(data, 0, data.length); // writing the
image
stream.close();
// show the saved thumb
savedthumb.source=newimagefile.nativePath;
bitmapje=null;
thumb=null;
// resize function
private function
resizeimage(image:BitmapData,maxx:Number,maxy:Number):BitmapData
var bmp:BitmapData =image;
var true_width:Number = bmp.width;
var true_height:Number = bmp.height;
var resize:Boolean=false;
if (true_width>maxx) resize=true;
if (true_height>maxy) resize=true;
if (resize==true)
var width:Number=maxx;
var height:Number = (width / true_width) * true_height;
true_width=width;
true_height=height;
if (true_height>maxy)
height=maxy;
width = (height/true_height)*true_width;
else
width=true_width;
height=true_height;
else
width=true_width;
height=true_height;
//new calculated width and heigt relative to the given maxx
and maxy.
width=Math.ceil(width);
height=Math.ceil(height);
//create a new image object with the calculated widht and
height for the smaller image
var mysmallimage:Image=new Image();
mysmallimage.width=width;
mysmallimage.height=height;
//new matrix for smaller image
var m : Matrix = new Matrix() ;
//scale the matrix to the correct sizes.
m.scale( mysmallimage.width / bmp.width, mysmallimage.height
/ bmp.height ) ;
//draw the image into the image object
mysmallimage.graphics.beginBitmapFill( bmp, m, false, true )
mysmallimage.graphics.drawRect( 0, 0, mysmallimage.width,
mysmallimage.height ) ;
mysmallimage.graphics.endFill();
//put the smaller image into bitmapdata so it can be
returned.
var littlebitmapdata:BitmapData=new
BitmapData(mysmallimage.width,mysmallimage.height,true,0x00000000);
littlebitmapdata.draw(mysmallimage);
// set the temporary small image to null so the GC can
remove it from the memmory.
mysmallimage=null;
bmp=null;
//returning the small image.
return littlebitmapdata;
// encoder to png
private function encodeToPng(bmd:BitmapData):ByteArray
var png:PNGEncoder= new PNGEncoder();
return png.encode(bmd);
]]>
</mx:Script>
<!--<mx:Image id="tempimage" x="404" y="36"
complete="temploadcomplete()"/>-->
<mx:Image id="myimg" x="10" y="55" width="314"
height="227" verticalAlign="middle" horizontalAlign="center"/>
<mx:TextInput id="imageurl" x="53" y="303" width="160"
maxWidth="160"/>
<mx:Button x="221" y="303" label="Bladeren"
click="imageFileDialog(myimg,imageurl)"/>
<mx:Image x="346" y="55" id="savedthumb"/>
<mx:Text x="23" y="0" text="Original image with limit
width and height to show it on the screen." height="47"
width="177"/>
<mx:Text x="346" y="0" text="Local stored thumbnail"/>
</mx:WindowedApplication>
To bad the attach code button still isn't fixed :(Hi there,
Will you be able to provide the backend script for saving the
file data?Will you be able to provide the backend script for saving
the file data?
This example is created for a desktop application. Saving the
file is included in this example, it saves in the application
storage directory.
// File.applicationStorageDirectory gets you to the local
storage dir
//On Windows, this is the "projectname" directory
//(for example, C:\Documents and Settings\application
data\projectname).
// On Mac OS, it is /Users/userName/Documents.
If you attempt to use certain functionality in a website, you
need other functionality for storing the image on the server. There
are lots of examples on that one.. Perhaps i need it in the future.
If i do i will post an example on the forum.
Also, may I post your link to other forums, so that others may
benefit?
Sure you may post the example on other websites and forums.
I found it difficult to find nice examples, so the more the
better ;)
Just put underneath the example something like:
Created By: Jacob Hingst From Holland
No copyright attached, so free for your use. -
Images as Buttons and Image Resizing in mxml
Sorry for all the questions but I've run into a problem when trying to create buttons that are just an image in mxml. When I first tried this I couldn't find a way to get the border around the button to dissapear so it ended up looking like my image had an extra black border around it. Then someone here suggested I just set the buttonMode property of an mx:Image to true which ended up working fine to a point. The problem I'm having is that even if I make the tabEnabled property of the image (that I'm using as a button) true, I can't tab over to it. Is there a way to either get rid of the black borders of a button or to make it so I can tab over to an image I'm using as a button?
My second question has to do with image resizing. Lets say I have an image of a horizontal line that I want to put at the top of the mxml page, and I want it to extend the full length of the page, even after the user has resized the browser. Is there a way to do that? I've tried putting the width as 100% or giving the image a "left" and "right" value so that presumably it would be stretched to fit within those but nothing has worked so far. Is there no way to do this or am I doing something wrong?
Thank you for any help you guys can give.Of course, sorry about that. So the following is a barebones example of how I currently implement buttons and images as buttons:
<mx:Button id="facebookButton" icon="@Embed(source='image.png')" width="30"/>
<mx:Image buttonMode="true" id="button" source="anotherimage.png" enabled="true" click="{foo()}"/>
And within the image I've tried making the tabFocusEnabled property true but to no avail.
The following is how I've tried stretching out an image across the whole page:
<mx:Image source="yetanotherimage.png" width="100%" scaleContent="true"/>
<mx:Image source="yetanotherimage.png" left="10" right="10" scaleContent="true"/>
Is this more helpful? -
Resize and crop images to a specific width and height
Hi,
I want to convert images to thumbnails with a 'standard' format - I need all images to have the same width and height.
So I need to resize and then crop the images. Is this possibe with JAI? Are there other libraries which can do this better?
I've read about ImageMagick - are the Java interfaces to ImageMagick good?
/best regards, Håkan Jacobsson - System developer in SwedenDuplicate posting, answers are here
http://forums.sun.com/thread.jspa?threadID=5419291
Pleas don't duplicate unless you note that you have done so and provide pointers to the duplicates - as I'm sure you're aware. . . -
Resizing images - portrait and landscape
Hi,
I am uploading and resizing images(see code), I want to
resize them to 200px by 150px if landscape and 150px by 200px if
portrait. How can I determine the orientation of the image?Well, first of all you would need to know what the initial
image dimensions are. And the way to do this is to get the current
images height and width from reading the image. You would then
compare the width number to the height number and if the width is
greater than the height, you know that it's more of a landscape
photo...and vice versa.
Try this code:
<cfimage action="read"
source="#expandPath("graphics/corner.png")#" name="myImage" />
<cfdump var="#variables.myImage#" />
<cfif variables.myImage.width gt
variables.myImage.height>
Landscape
<cfelseif variables.myImage.width lt
variables.myImage.height>
Portrait
<cfelseif variables.myImage.width eq
variables.myImage.height>
Square
<cfelse>
Something else for whatever reason.
</cfif>
At least, I think this is how you'd do it. I know it's not
the most elegant way...you might want to look at ColdFusion image
functions rather than reading the whole image in, I think there are
functions just to get width and height, which I imagine should give
you better performance.
Good luck,
Mikey. -
When I have resized and saved an image in Photoshop (CS, version 8.0 for Mac) using image size, why is it so large when I open it in preview or another image viewer? Has it actually saved according to the size I specified?
You want to view the image at the Print Size, which represents the size that shows in the Image>Resize Dialog.
View>Print Size
Since screen resolution is almost always lower that the print resolution (somewhere between 72 and 96 usually), images will always look bigger on the screen, unless you view them at print size.
(apple Retina displays have a much higher resolution than normal screens, closer to the average print size resolution)
more info:
Photoshop Help | Image size and resolution
Maybe you are looking for
-
Receiver File Error while using Dynamic Configuration
Hi All, My Scenario is from SAP IDOC --> PI --> FIle... In the mapping i have used the dynamic variable substitution for the receiver file.... The Dyanamic file will be alwasy generated irrespective of the condition for the Mapping... Now Whenever SA
-
AUR won't accept PKGBUILD with numbers in the Package Name
Trying to submit a PKGBUILD called: gstreamer0.10-pitfdll-cvs I am getting an error "Invalid name: only lowercase letters are allowed." Does this mean that numbers are not allowed in the package names in AUR? The error goes away once I remove the num
-
Can delegate and strategy patterns coexist ?
Say I have an interface for persistence call that PersistenceInterface. Now for MySQL I created MySQLPersistenceClass and for DB2 I created one more class DB2PersistenceClass. Now to proceed with my busines slogic I have a class BusinessLogicHandler
-
Help connecting an external hard drive
ok, so I had my Maxtor 5000DV conncected to my old PC and everything was fine. Now I'm trying to connect it to my Macbook and everything comes up as read only. I'm really new to Macs so please help. Should I reformat the external hard drive so I can
-
Please help me to embed the Flash control in a Windows application (using Visual Studio)
How to create and control Datagrid Using XML in Flash 8.0? Is it possible to create the dynamic row/columns in flash using XML? How can I insert the picutes and text fileds in flash datagrid usig XML? Please provide me articles or examples (.fla) rel