By visual inspection of an 1200 pixels image scaled to 0.5 using the above
code any diferences are indistinguishable to my eye.

2016-08-31 22:40 GMT+02:00 Jens Axel Søgaard <jensaxelsoega...@gmail.com>:

> Is the result as good as ImageMagick?
>
> Den 31. aug. 2016 kl. 22.25 skrev Tobias Gerdin <tger...@gmail.com>:
>
> Right, that did it, thanks!
>
> 2016-08-31 14:19 GMT+02:00 WarGrey Gyoudmon Ju <juzhenli...@gmail.com>:
>
>> Try this example,
>>
>> (require racket/draw)
>>
>> (define bitmap-blank
>>   (lambda [[w 0] [h #false] #:backing-scale [backing-scale 2.0]]
>>     (define width  (max 1 (exact-ceiling w)))
>>     (define height (max 1 (exact-ceiling (or h w))))
>>     (make-bitmap width height #:backing-scale backing-scale)))
>>
>> (define bitmap-scale
>>   (case-lambda
>>     [(bmp scale)
>>      (if (= scale 1.0) bmp (bitmap-scale bmp scale scale))]
>>     [(bmp scale-x scale-y)
>>      (cond [(and (= scale-x 1.0) (= scale-y 1.0)) bmp]
>>            [else (let ([w (max 1 (exact-ceiling (* (send bmp get-width)
>> scale-x)))]
>>                        [h (max 1 (exact-ceiling (* (send bmp get-height)
>> scale-y)))])
>>                    (define dc (make-object bitmap-dc% (bitmap-blank w h)))
>>                    (send dc set-smoothing 'aligned)
>>                    (send dc set-scale scale-x scale-y)
>>                    (send dc draw-bitmap bmp 0 0)
>>                    (or (send dc get-bitmap) (bitmap-blank)))])]))
>>
>> I use it in my project.
>> The algorithm is exact what Jens says.
>>
>> On Wed, Aug 31, 2016 at 5:17 AM, Jens Axel Søgaard <jensa...@soegaard.net
>> > wrote:
>>
>>> Hi Tobias,
>>>
>>> I call the below procedure with `in` equal to a 1300-pixel wide PNG
>>>> image, w=320 and `out` equal to a nice path. Even so, the `out` image
>>>> remains 1300 pixels wide (i.e. it's not resized).
>>>>
>>>> (define (racket-resize in w out)
>>>>   (let ([bitmap (read-bitmap in)])
>>>>     (let ([orig-width (send bitmap get-width)])
>>>>       (let ([dc (send bitmap make-dc)]
>>>>             [s (/ w orig-width)])
>>>>         (send dc scale s s))
>>>>       (send bitmap save-file out 'png))))
>>>>
>>>> What am I doing wrong?
>>>>
>>>
>>> The problem is that scale doesn't change the bitmap.
>>> The scale affects how the logical coordinates of the drawing context
>>> are translated into bitmap coordinates.
>>>
>>> In order to resize a bitmap:
>>>
>>>    1. Create a new bitmap with the new size.
>>>    2. Get the dc for the new bitmap
>>>    3. Set the scale of dc
>>>    4. Use draw-bitmap using the old image as the source
>>>    5. Save the new bitmap
>>>
>>> (untested)
>>>
>>> /Jens Axel
>>>
>>>
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Racket Users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to racket-users+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to