Moving an image with fs causes it to corrupt - upload

I'm using AdonisJS framework, and it has its own method move(), that uses fs.
The issue is that when making use of this method, the image that's moved is corrupted, and when oepning it, this message is shown:
Error interpreting JPEG image file (Not JPEG file: starts with 0xef 0xbf)
The documentation I based on is this, so my code is no much different than it.

Related

Acces Violation during .png saving

When I try to call SaveToFile method on TPNGImage object I get Acces Violation Error.
PNG Construction:
pngTest:=TPngImage.CreateBlank(COLOR_GRAYSCALE, 16, 2048, 2048);
Method Call: pngTest.SaveToFile('testtttt.png');
PNG object is created correctly because I can assign it to TImage and it works.
This is a defect in the Delphi PNG library code. Please report it to Embarcadero.
The defect seems to be triggered by the use of 16 bit colour depth. If you switch the code to use 8 bit colour then the code runs successfully.
There's no simple workaround, and so you'll need to find a different PNG library if you wish to continue with 16 bit colour. I would expect that Microsoft's Windows Imaging Component library will function correctly. Or you might consider Graphics32 with the GR32PNG extension.

How do you load an Image server side in dart?

I've seen the answers for using an ImageElement to load an image. This only works on the browser side and I wanted to do some processing on the server.
Is there any way to load and read RGBA values from a PNG in server side dart? If not are there any server side image processing libraries planned?
Is there anyway to run Dartium "headless" so I can use the canvas api to do what I want?
There is a dart library that can read and write PNG images server side,
http://pub.dartlang.org/packages/image
The library can read and write PNG and JPG images, and provides a number of image manipulation commands.
For example, to read a PNG, resize it, and save it to disk using this library:
import 'dart:io' as Io;
import 'package:image/image.dart';
void main() {
// Read a PNG image from file.
Image image = readPng(new Io.File('foo.png').readAsBytesSync());
// Resize the image to a 120x? thumbnail (maintaining the aspect ratio).
Image thumbnail = copyResize(image, 120);
// Save the thumbnail to disk as a PNG.
new Io.File('foo-thumbnail.png').writeAsBytesSync(writePng(thumbnail));
}
There is no library out there at the moment.
I have been using ImageMagick instead. You could use Process.run() to run it. Here's an example:
Process.run('/usr/local/bin/convert', ['file', '-resize', '100x100']);

crash in cvBlobsLib VS2008

I am using cvBlobsLib library for a blob detection work, however, i am facing a crash in the program in the code.
My code crashes at this point:
CBlobResult blobs;
blobs = CBlobResult(imageSkinPixels, NULL, 0);
imageSkinPixels must be a single-channel image: in other words, you need to convert your RGB image to GRAY before passing it to CBlobResult().
Also, we don't know what is the type of imageSkinPixels, but it should be a pointer to IplImage.
That's all I can say with the code you shared. If this doesn't fix the problem you'll need to share more code.

OpenCV Line-Mod problems with Images

I'm trying to use line-mod (in special line-2d) in opencv 2.4 to compare images. At the moment I try to change the test-implementation linemod.cpp to use an input images instead of the camera, but without any success.
I tried to load an image via imread('...', CV_LOAD_IMAGE_COLOR); and pushed that in the sources vector but got a 'OpenCV Error: Assertion failed (response_map.rows % T == 0) in linearize' error.
If I load a CV_LOAD_IMAGE_GRAYSCALE image the run stops at detector->match with the error 'Thread 1: EXC_BAD_ACCESS (code=1, address=0x11310f000)'.
I don't understand what makes the difference between images coming from a VideoCapturer and from imread...
Is there anyone out there that may help me? I'm totally lost ... again ;-)
(For example sample code for matching two objects from images with linemod would be absolutely great!)
I use opencv 2.4 with xcode on a mac.
Maybe it is too late for an answer, but I am also interested in the algorithm
In the OpenCV Minutes 2012-06-26 ( http://code.opencv.org/projects/opencv/wiki/2012 ) you can read:
Will work with Stefan Hinterstoisser for final version of LINEMOD by September
So if you did not already solve it, you may want to wait.

Compressing BitmapData

The situation is this:
I've written a simple MovieClip replacement that converts an existing imported MovieClip to a sequence of BitmapData. This removes the requirement for Flash to render vector data in the MovieClip on each frame.
But BitmapData has a huge memory footprint. I've tried converting the BitmapData to a ByteArray and using the compress() method. This results in a significantly smaller memory footprint. But it has proven impractical. For each redraw, I tried uncompressing()'ing the ByteArray, then using SetPixels to blit the data to the screen, then re-compressing() the frame. This works but is terribly slow.
So I was wondering if anybody else has an approach I could try. In Flash, is it possible to compress bitmap data in memory and quickly blit it to the screen?
I wonder how native animated GIFs work in Flash. Does it uncompress them to BitmapData behind the scenes, or is frame decompression done on the fly?
Perhaps there is an Alchemy project that attempts to blit compressed images?
Thanks for any advice you can offer :)
#thienhaflash's response is good but has aged a year and since then Flash Player and AIR Runtime have expanded their capabilities. Today I stumbeled on this little tidbit from Adobe's AS3 Guide. As of player 11.3 there are native image compression techniques available. Here's a snippet:
// Compress a BitmapData object as a JPEG file.
var bitmapData:BitmapData = new BitmapData(640,480,false,0x00FF00);
var byteArray:ByteArray = new ByteArray();
bitmapData.encode(new Rectangle(0,0,640,480), new flash.display.JPEGEncoderOptions(), byteArray);
Not sure about the practicality for blitting but it's nice that it can be done natively.
For memory reservation you need to think twice before convert a MovieClip to a Bitmap sequence. Is it really that need ? Can you break things down as there are several things (like the background) is static (or just moving around) why don't cache bitmap for each elements instead of one big Bitmap sequence ?
I usually used AnimatedBitmap (the name for bitmap sequence alternative for a MovieClip) only for small size animated icons, and other heavy calculation stuffs (like fire / smoke effects ...). Just break things down as much as you can !
As far as i know, there are no way to compress the memory used by a BitmapData located in the memory and there are nothing related to Alchemy could help improve memory used in this case.
Animated GIF won't works in Flash natively, you will need some library to do that. Search for AnimatedGIF as3 library from bytearray.com, actually the library just read the gif file in raw byteArray and convert to an animatedBitmap just like how you've done.
this is an old question, but there is recent info on this : jackson Dunstan has had a run with bitmapdatas and it turns out that Bitmap data obtained from compressed sources will "deflate" after some time unused.
here are the articles : http://jacksondunstan.com/articles/2112, and the two referred at the beginning of it.
So you could absolutely do something like :
var byteArray:ByteArray = new ByteArray();
myBitmapData.encode(new Rectangle(0,0,640,480), new flash.display.JPEGEncoderOptions(), byteArray);
var loader = new Loader();
loader.addEventListener(Event.COMPLETE, function(_e:Event):void{
if(loader.content is Bitmap){
myBitmapData.dispose()
myBitmapData= Bitmap(loader.content).bitmapData;
}
});
loader.loadBytes(byteArray);
I'm not sure if it would work as is, and you definitely want to handle your memory better. but now, myBitmapData will be uncompressed when you try to read from it, and then re-compressed when you don't use it for about ten seconds.

Resources