[racket] processing images...

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Mon Apr 11 14:09:38 EDT 2011

On Mon, Apr 11, 2011 at 12:16 PM, geb a <geb_a at yahoo.com> wrote:
> Hello all,
> I'm having some trouble processing a block of pixels from an image. I want to grab some portion of image, do something to it, and save it to a file.  In this example, I grab a portion of an image and save it to a file but the image in the file is corrupted.  Evidently I'm doing something wrong.  I've spent a number of hours trying to figure it out, but I'm blind to the problem.  I would be very grateful for any help someone can give me.
> Sincerely,
> Dan Anderson
> #lang racket/gui
> ; define the portion of the image I want to process
> (define x 0)
> (define y 0)
> (define w 10)
> (define h 10)
> (define bm (make-object bitmap% "4colors.jpg"))

Use make-bitmap these days (but this doesn't seem to be the problem)

> (define pixels (make-bytes (* w h 4) 0)) ;each pixel has four numbers
> (send bm get-argb-pixels x y w h pixels true) ; get the block of pixels
> pixels ;check that there is information in pixels
> ;make a new bitmap of the section
> (define nbm (make-object bitmap% pixels w h))
> (send nbm save-file "test.png" 'png)

I think that doesn't do what you wanted. I think you need to call
set-argb-pixels (the constructor is doing something with black & white
pixels or something, not the same thing as get-argb-pixels).


Posted on the users mailing list.