Home Delphi JPEG resize and Compress
Reply: 2

Delphi JPEG resize and Compress

yilmazca Published in 2018-02-12 10:49:22Z

I have a some problems before saving image on TJPEGImage.

step 1: *(JPEG) I want add some text "on top of the picture" a new line.. not on image.. how can I do that?

step 2: * I want resize image to (cm) example : 200cm x 300cm / 320DPI etc..

step 3 *Save JPEG with compress What is the best lossless method ?

I was try DEVEXPRESS image component but it saved image 400MB... I couldnt find any compress method.

any Can help me ? thank you all

Deltics Reply to 2018-02-12 19:58:40Z

JPEG is typically intrinsically compressed, although there is a lossless variant (which is also compressed, just in a different way that avoids loss).

I'm not familiar with the DevExpress facilities for handling JPEG's specifically, but any properties to do with JPEG handling will (should) almost certainly provide control over the degree of compression to be used which may or may not include an option for Lossless.

However, based on the resulting file size you are seeing, there is compression occurring in your case.

If you are resizing to 200cm x 300cm (78" x 118") at 320 dpi then your resulting image is (in round numbers) 25,000 x 38,000 px. That's a 950 MEGAPIXEL image!

The lossless (least compressed) JPEG representation of such an image would be over 1GB in size so if you are getting "only" 400MB then there clearly is some quite significant compression already at work.

Your problem is that you appear to want to compress the image more (to make the size smaller than 400MB) AND you want to use lossless compression, which would mean compressing it less (and make the file size larger).

So I think you need to decide what you really want (and you might then find you already have it).

dawood karimy
dawood karimy Reply to 2018-02-13 07:15:00Z

you should save your jpeg image to bitmap first using

bmp.Canvas.TextOut(5, 5, 'SomeText');

and then resize the bitmaps i use this function

procedure SmoothResize(Src, Dst: TBitmap);
  x, y: Integer;
  xP, yP: Integer;
  xP2, yP2: Integer;
  SrcLine1, SrcLine2: pRGBArray;
  t3: Integer;
  z, z2, iz2: Integer;
  DstLine: pRGBArray;
  DstGap: Integer;
  w1, w2, w3, w4: Integer;
  Src.PixelFormat := pf24Bit;
  Dst.PixelFormat := pf24Bit;

  if (Src.Width = Dst.Width) and (Src.Height = Dst.Height) then
    DstLine := Dst.ScanLine[0];
    DstGap  := Integer(Dst.ScanLine[1]) - Integer(DstLine);

    xP2 := MulDiv(pred(Src.Width), $10000, Dst.Width);
    yP2 := MulDiv(pred(Src.Height), $10000, Dst.Height);
    yP  := 0;

    for y := 0 to pred(Dst.Height) do
      xP := 0;

      SrcLine1 := Src.ScanLine[yP shr 16];

      if (yP shr 16 < pred(Src.Height)) then
        SrcLine2 := Src.ScanLine[succ(yP shr 16)]
        SrcLine2 := Src.ScanLine[yP shr 16];

      z2  := succ(yP and $FFFF);
      iz2 := succ((not yp) and $FFFF);
      for x := 0 to pred(Dst.Width) do
        t3 := xP shr 16;
        z  := xP and $FFFF;
        w2 := MulDiv(z, iz2, $10000);
        w1 := iz2 - w2;
        w4 := MulDiv(z, z2, $10000);
        w3 := z2 - w4;
        DstLine[x].rgbtRed := (SrcLine1[t3].rgbtRed * w1 +
          SrcLine1[t3 + 1].rgbtRed * w2 +
          SrcLine2[t3].rgbtRed * w3 + SrcLine2[t3 + 1].rgbtRed * w4) shr 16;
        DstLine[x].rgbtGreen :=
          (SrcLine1[t3].rgbtGreen * w1 + SrcLine1[t3 + 1].rgbtGreen * w2 +

          SrcLine2[t3].rgbtGreen * w3 + SrcLine2[t3 + 1].rgbtGreen * w4) shr 16;
        DstLine[x].rgbtBlue := (SrcLine1[t3].rgbtBlue * w1 +
          SrcLine1[t3 + 1].rgbtBlue * w2 +
          SrcLine2[t3].rgbtBlue * w3 +
          SrcLine2[t3 + 1].rgbtBlue * w4) shr 16;
        Inc(xP, xP2);
      end; {for}
      Inc(yP, yP2);
      DstLine := pRGBArray(Integer(DstLine) + DstGap);
    end; {for}
  end; {if}

and then save back them to jpeg image

JPG.CompressionQuality := 99;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.343152 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO