Use visible size information when copying macOS image from clipboard.

This commit is contained in:
ManoloFLTK 2020-01-18 17:09:10 +01:00
parent ed0c443253
commit ea09ea1009
2 changed files with 5 additions and 5 deletions

View File

@ -98,7 +98,7 @@ public:
#endif #endif
Fl_Image *oldimg = image_box->image(); Fl_Image *oldimg = image_box->image();
delete oldimg; delete oldimg;
im->scale(image_box->w(), image_box->h()); if (im->w() > image_box->w() || im->h() > image_box->h()) im->scale(image_box->w(), image_box->h());
image_box->image(im); // show the scaled image image_box->image(im); // show the scaled image
image_size->copy_label(title); image_size->copy_label(title);
value(image_box->parent()); value(image_box->parent());

View File

@ -3576,12 +3576,12 @@ static Fl_RGB_Image* get_image_from_clipboard(Fl_Widget *receiver)
if (!bitmap) return NULL; if (!bitmap) return NULL;
int bytesPerPixel([bitmap bitsPerPixel]/8); int bytesPerPixel([bitmap bitsPerPixel]/8);
int bpr([bitmap bytesPerRow]); int bpr([bitmap bytesPerRow]);
int bpp([bitmap bytesPerPlane]); int hh([bitmap pixelsHigh]);
int hh(bpp/bpr); int ww([bitmap pixelsWide]);
int ww(bpr/bytesPerPixel);
uchar *imagedata = new uchar[bpr * hh]; uchar *imagedata = new uchar[bpr * hh];
memcpy(imagedata, [bitmap bitmapData], bpr * hh); memcpy(imagedata, [bitmap bitmapData], bpr * hh);
Fl_RGB_Image *image = new Fl_RGB_Image(imagedata, ww, hh, bytesPerPixel); Fl_RGB_Image *image = new Fl_RGB_Image(imagedata, ww, hh, bytesPerPixel, (bpr == ww * bytesPerPixel ? 0 : bpr) );
image->scale([bitmap size].width, [bitmap size].height);
image->alloc_array = 1; image->alloc_array = 1;
[bitmap release]; [bitmap release];
Fl::e_clipboard_type = Fl::clipboard_image; Fl::e_clipboard_type = Fl::clipboard_image;