public function bmdToStr(bmd:BitmapData,width:int,height:int):String {
var encoder:JPEGEncoder = new JPEGEncoder();
var encBytes:ByteArray = encoder.encode(bmd);
return ImageSnapshot.encodeImageAsBase64(new ImageSnapshot(width,height,encBytes,"image/jpeg"));
}
As of now, I am creating JPEG image from bitmapdata as above.
I can use PNGEncoder for creating png images as well.
How do I create .bmp or .gif files?
why would you create BMP? and for the same matter, why would you create a GIF?
the only interesting thing about GIF is, it supports animation. apart from that it's simply deprecated. if you want lossless compresion use PNG, if size is more important, use JPG. if it is really animation you want, I suggest you have a look at GIF Animation Encoder.
and BMP is totally not worth any consideration. it's just huge for 24 bit images (32 with transparency). an image 800x600 will result in 1.4 MB. BMP offers no advantages except the fact that it doesn't require decompression for display, but nowadays this makes virtually no difference, especially for the web.
if you really think, you need it, then you should simply lookup bmp specs. it's really straight forward.
Related
It is difficult to have full control over how pdf document is rendered on the web browser (adjusting the zoom, page size, etc.) when it is embedded in an html document. So, I am considering to convert pdf documents in advance into formats such as svg or png, and embed them into an html document instead of embedding a pdf file. A multi-page pdf document will correspond to multiple files of svg or png, which will be stored in a directory. I can handle the change of page according to the user input using JavaScript, and that is not a problem.
Given that the pdf documents are scanned documents at around 300dpi, black and white, and the converted file should have a comparable quality, what format would be best suited for this situation mostly in terms of rendering speed on the browser? I understand that cache will change the speed, so I want to limit my consideration to when the pages are rendered for the first time. I have svg or png in mind. Which one is better, or is there a better format that can be easily be converted to from pdf?
When a bitmap document such as png is zoomed to a different size, I understand that it will be jaggy. On the other hand, if I feel that, if I have a svg file that embeds such scanned parts, anti-aliasing will work, removing the jagginess. Is my understanding correct?
what format would be best suited for this situation mostly in terms of rendering speed on the browser?
Once it is in the browser, the bitmap (PNG) will be faster. However if the PDF is mostly text and vectors, it will generally be a lot faster to first viewing. Downloading is usually slower than rendering.
If the PDF just consists of high resolution scans, then the two approaches will be roughly equivalent in terms of speed.
if I have a svg file that embeds such scanned parts, anti-aliasing will work, removing the jagginess. Is my understanding correct?
No, that is not correct. A bitmap image does not magically have infinite resolution when put inside an SVG. If you scale up the SVG, the bitmap inside will still get jaggy. Same as if it wasn't in an SVG.
I have not found a way up until now to save an image as png into the isolated storage. The only save for images i found was the SaveJpeg(), but that way i loose the transperancy of the image. Does anyone know of another method that allows you to save the BitMapImage as .png to the IsolatedStorage?
ImageTools supports working with PNGs (encoding and decoding)
Plus, it has been asked a number of times... Saving Bitmap as PNG on WP7
My logic was incorrect. I was attempting to take a jpeg and then convert it to png which ended up in me loosing my transparency. I overlooked the fact that the "screenshot" feature i was using saved the stream to jpeg and then reused it. My mistake, I need to figure out how i can take a screenshot as png
I need to do OCR on a group of images. I have been using Tessnet and it works pretty well. The problem is that it seems to have problems with some images, so I thought that it might work better if I modify the images' brightness, contrast, etc. Also, the images are in .jpg format, but I read that .tiff is optimal.
What can I do? Should I just convert the JPEGs to TIFFs?
There's no point in converting the jpeg images to a lossless format like tiff, you will convert the artifacts as well. You could try and apply a sharpness kernel on the image before you try to do ocr on it.
Look at this page for more information.
In AS3, I am loading a png from a zip file (nochump's zip library through ByteArray to Loader). The png can be up to 45k pixels wide but only 120 tall. This creates a problem in flash, as images can only be ~8000 pixels wide. A possible solution would be to split the images into 6 columns somehow. This would probably need to be done in the ByteArray state, because the limitation is in Bitmap and Loader. Would this even be possible?
I believe you should use Alchemy to decode such a large file and put it in a Byterray. It looks like it has been done for JPEG, PNG shouldn't be very different!
http://segfaultlabs.com/devlogs/alchemy-loading-large-jpeg-images
All things are possible since you have the bytes. However this would require you to write a complete png library in actionscript. PNG is a very complicated and sophisticated compressed image format, so you can't just shred the image into blocks by copying portions of the ByteArray.
So really, the answer is no, it is not possible. Sorry.
If it was an uncompressed BMP on the other hand you would be in with a chance. However I suspect that if you are able to change the format of the file, it would be easier to pre-split the image into columns.
What's the fastest way to get a screen capture in flex? I am currently using: (I currently encode it to Base64 for upload to a webserver, but this is not necessarily required. All I want is an image file to appear on the server).
ImageSnapshot.defaultEncoder = JPEGEncoder;
var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(<< flex component >>);
var screenshotData:String = ImageSnapshot.encodeImageAsBase64(imageSnap);
It currently holds up the entire application for almost a second as it actually captures the image. The Base64 encoding happens essentially instantaneously.
Check out the fllowing URL, it is an open source JPEG encoder which is over 4 times faster than the one in corelibs.
http://www.bytearray.org/?p=775
Take a look at the answer to this: Thumbnails of components
I've used a very similar function and it was pretty fast, so hopefully you'll have no problem doing it that way.
The open-source JPEG encoder is not any faster than the mx.codecs one, unfortunately. However, the build in PNG encoder is about 6x as fast as the JPEG encoder. This solves the problem that I was currently having, i.e. too slow compression.
The "thumbnails of components" answer from CookieOfFortune solves another problem, that of taking the snapshot separately from compression, (snapshotting takes ~5ms for me, compression, now, <500ms).