Changeset 108 for trunk/UContactImage.pas
- Timestamp:
- Feb 11, 2022, 11:31:42 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UContactImage.pas
r103 r108 9 9 10 10 type 11 TContactImageFormat = (if Bmp, ifJpeg, ifPng, ifGif);11 TContactImageFormat = (ifNone, ifBmp, ifJpeg, ifPng, ifGif); 12 12 13 13 { TContactImage } … … 64 64 (ContactProperty.Attributes.IndexOf('png') <> -1) then Result := ifPng 65 65 else 66 Result := ifBmp; 66 if (ContactProperty.Attributes.IndexOf('BMP') <> -1) or 67 (ContactProperty.Attributes.IndexOf('bmp') <> -1) then Result := ifBmp 68 else 69 Result := ifNone; 67 70 end; 68 71 … … 134 137 GifImage.Free; 135 138 end; 139 end else 140 if ImageFormat = ifBmp then begin 141 try 142 Bitmap.SaveToStream(Stream); 143 except 144 end; 136 145 end else begin 137 // Bmp 138 try 139 Bitmap.SaveToStream(Stream); 140 except 141 end; 146 // Use default type 147 SaveImageToStream(ifJpeg, Stream); 142 148 end; 143 149 end; … … 149 155 PngImage: TPortableNetworkGraphic; 150 156 GifImage: TGIFImage; 157 BmpImage: TBitmap; 151 158 begin 152 159 if ImageFormat = ifJpeg then begin 153 JpegImage := TJPEGImage.Create;154 try160 try 161 JpegImage := TJPEGImage.Create; 155 162 try 156 163 JpegImage.LoadFromStream(Stream); … … 160 167 Canvas.Draw(0, 0, JpegImage); 161 168 end; 162 Used := True;163 except164 Used := False;165 end;166 finally167 JpegImage.Free;169 finally 170 JpegImage.Free; 171 end; 172 Used := True; 173 except 174 Used := False; 168 175 end; 169 176 end else 170 177 if ImageFormat = ifPng then begin 171 PngImage := TPortableNetworkGraphic.Create;172 try178 try 179 PngImage := TPortableNetworkGraphic.Create; 173 180 try 174 181 PngImage.LoadFromStream(Stream); … … 178 185 Canvas.Draw(0, 0, PngImage); 179 186 end; 180 Used := True;181 except182 Used := False;183 end;184 finally185 PngImage.Free;187 finally 188 PngImage.Free; 189 end; 190 Used := True; 191 except 192 Used := False; 186 193 end; 187 194 end else 188 195 if ImageFormat = ifGif then begin 189 GifImage := TGIFImage.Create;190 try196 try 197 GifImage := TGIFImage.Create; 191 198 try 192 199 GifImage.LoadFromStream(Stream); … … 196 203 Canvas.Draw(0, 0, GifImage); 197 204 end; 198 Used := True; 199 except 200 Used := False; 201 end; 202 finally 203 GifImage.Free; 205 finally 206 GifImage.Free; 207 end; 208 Used := True; 209 except 210 Used := False; 211 end; 212 end else 213 if ImageFormat = ifBmp then begin 214 try 215 BmpImage := TBitmap.Create; 216 try 217 BmpImage.LoadFromStream(Stream); 218 with Bitmap do begin 219 PixelFormat := pf24bit; 220 SetSize(BmpImage.Width, BmpImage.Height); 221 Canvas.Draw(0, 0, BmpImage); 222 end; 223 finally 224 BmpImage.Free; 225 end; 226 Used := True; 227 except 228 Used := False; 204 229 end; 205 230 end else begin 206 // Bmp207 with TImage.Create(nil) do208 try231 // Unknown image type, let TPicture guess what it is 232 try 233 with TImage.Create(nil) do 209 234 try 210 235 Picture.LoadFromStream(Stream); 211 Canvas.Draw(0, 0, Picture.Bitmap); 212 Used := True; 213 except 214 Used := False; 215 end; 216 finally 217 Free; 236 with Bitmap do begin 237 PixelFormat := pf24bit; 238 SetSize(Picture.Bitmap.Width, Picture.Bitmap.Height); 239 Canvas.Draw(0, 0, Picture.Bitmap); 240 end; 241 finally 242 Free; 243 end; 244 Used := True; 245 except 246 Used := False; 218 247 end; 219 248 end;
Note:
See TracChangeset
for help on using the changeset viewer.